Package com.tnsai.observability.events
Class Slf4jAgentEventPublisher
java.lang.Object
com.tnsai.observability.events.Slf4jAgentEventPublisher
- All Implemented Interfaces:
AgentEventPublisher
Default
AgentEventPublisher — JSON-serializes the event and
writes it via SLF4J at the level corresponding to EventLevel.
Logstash encoder (or any structured-log sink) then picks the JSON up.
One logger per event type so consumers can filter
(com.tnsai.events.ToolCallStartEvent can be silenced or routed
separately from com.tnsai.events.ErrorEvent).
The serialized payload shape:
{
"eventId": "abc123",
"eventType": "ChatEvent",
"timestamp": "2026-04-23T20:00:00Z",
"level": "INFO",
"context": { "tenantId": "...", "agentId": "...", ... }
}
- Since:
- 0.5.0 (issue #78)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisEnabled(EventLevel level) Should this publisher emit at the given level?voidpublish(TnsAIEvent event) Publish a single event.voidpublish(TnsAIEvent event, EventLevel level, EventContext context) Publish a single event with explicit level / context overrides.
-
Constructor Details
-
Slf4jAgentEventPublisher
public Slf4jAgentEventPublisher()Default: emit every level. -
Slf4jAgentEventPublisher
- Parameters:
threshold- minimum level to emit; events below this level are dropped.
-
-
Method Details
-
publish
Description copied from interface:AgentEventPublisherPublish a single event. Implementations must be safe to call from any thread; they may queue, batch, or write directly. Errors during publication must not propagate to the caller — log and drop.- Specified by:
publishin interfaceAgentEventPublisher
-
publish
Description copied from interface:AgentEventPublisherPublish a single event with explicit level / context overrides. Useful when emitting an event at a level different from the event's default (e.g. demoting a verbose ChatEvent to DEBUG in production).Default implementation ignores overrides — concrete publishers that care about level filtering (Slf4j) override this.
- Specified by:
publishin interfaceAgentEventPublisher
-
isEnabled
Description copied from interface:AgentEventPublisherShould this publisher emit at the given level? Used to short-circuit expensive event construction when the publisher will discard the event anyway.Default: always true (no level filtering).
- Specified by:
isEnabledin interfaceAgentEventPublisher
-