Package com.tnsai.observability.events
Class AgentEvents
java.lang.Object
com.tnsai.observability.events.AgentEvents
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 Summary
Modifier and TypeMethodDescriptionstatic voidpublish(TnsAIEvent event) Publishes the event at INFO level with the current thread's context.static voidpublish(TnsAIEvent event, EventLevel level) Publishes at the given level; current thread's context is captured.static voidpublish(TnsAIEvent event, EventLevel level, EventContext context) Publishes with explicit level + context (bypasses thread-local lookup).static AgentEventPublisherstatic voidRestore the SPI-resolved publisher (default).static voidsetPublisher(AgentEventPublisher publisher) Override the publisher — primarily for tests.
-
Method Details
-
publish
Publishes the event at INFO level with the current thread's context. -
publish
Publishes at the given level; current thread's context is captured. -
publish
Publishes with explicit level + context (bypasses thread-local lookup). -
publisher
- Returns:
- the currently active publisher (composite if multiple SPI sinks).
-
setPublisher
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).
-