Class Slf4jAgentEventPublisher

java.lang.Object
com.tnsai.observability.events.Slf4jAgentEventPublisher
All Implemented Interfaces:
AgentEventPublisher

public class Slf4jAgentEventPublisher extends Object implements 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 Details

    • Slf4jAgentEventPublisher

      public Slf4jAgentEventPublisher()
      Default: emit every level.
    • Slf4jAgentEventPublisher

      public Slf4jAgentEventPublisher(EventLevel threshold)
      Parameters:
      threshold - minimum level to emit; events below this level are dropped.
  • Method Details

    • publish

      public void publish(TnsAIEvent event)
      Description copied from interface: AgentEventPublisher
      Publish 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:
      publish in interface AgentEventPublisher
    • publish

      public void publish(TnsAIEvent event, EventLevel level, EventContext context)
      Description copied from interface: AgentEventPublisher
      Publish 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:
      publish in interface AgentEventPublisher
    • isEnabled

      public boolean isEnabled(EventLevel level)
      Description copied from interface: AgentEventPublisher
      Should 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:
      isEnabled in interface AgentEventPublisher