Class AgentEvents

java.lang.Object
com.tnsai.observability.events.AgentEvents

public final class AgentEvents extends Object
Static facade for publishing observability events from anywhere in the framework or consumer code.

Resolves the active AgentEventPublisher once (via SpiLoader, falling back to Slf4jAgentEventPublisher when nothing is registered) and provides a thin call site:


 AgentEvents.publish(myEvent);
 AgentEvents.publish(myEvent, EventLevel.WARN);
 

The resolved publisher is settable for tests:


 var capturer = new CapturingAgentEventPublisher();
 AgentEvents.setPublisher(capturer);
 try {
     // run code under test
 } finally {
     AgentEvents.resetPublisher();
 }
 

Multiple SPI-registered publishers are auto-composed via CompositeAgentEventPublisher so consumers can drop a JAR with a new publisher and have it fan out alongside the defaults.

Since:
0.5.0 (issue #78)
  • Method Details

    • publish

      public static void publish(TnsAIEvent event)
      Publishes the event at INFO level with the current thread's context.
    • publish

      public static void publish(TnsAIEvent event, EventLevel level)
      Publishes at the given level; current thread's context is captured.
    • publish

      public static void publish(TnsAIEvent event, EventLevel level, EventContext context)
      Publishes with explicit level + context (bypasses thread-local lookup).
    • publisher

      public static AgentEventPublisher publisher()
      Returns:
      the currently active publisher (composite if multiple SPI sinks).
    • setPublisher

      public static void setPublisher(AgentEventPublisher publisher)
      Override the publisher — primarily for tests. Consumers in production should rely on SPI auto-discovery.
    • resetPublisher

      public static void resetPublisher()
      Restore the SPI-resolved publisher (default).