Package com.tnsai.observability.events
Record Class EventContext
java.lang.Object
java.lang.Record
com.tnsai.observability.events.EventContext
public record EventContext(String tenantId, String sessionId, String traceId, String spanId, String agentId, String agentClass, String role, List<String> capabilities, Optional<String> groupId, Optional<String> conversationId, Map<String,String> extensions)
extends Record
Correlation context attached to every observability event.
Carries the framework identity required to route a log line back to the
agent / role / session / tenant that produced it. Populated automatically
by framework entry points via AgentContext.enter(EventContext) and
consumed by the AgentEventPublisher chain (and indirectly by
SLF4J MDC, which is kept in sync).
Field semantics
- tenantId — multi-tenant scope (e.g.
"acme").null/blank if not multi-tenant. - sessionId — user-interaction scope (one chat turn or the lifetime of a long-running session).
- traceId / spanId — OTel correlation. Set by the trace provider; mirrored into MDC for log/trace correlation in vendors like Datadog, Honeycomb, Tempo.
- agentId / agentClass — which agent instance produced the event and its concrete class.
- role — active role at event time.
- capabilities — capability ids active in this scope (used for capability-level error budgets in #92).
- groupId — present iff the agent is running inside an
AgentGroup. - conversationId — present for multi-turn conversations (orthogonal to sessionId; a session can span conversations).
- extensions — operator-defined string→string fields (deployment, region, customer cohort, …). Kept low-cardinality.
All collection fields are defensively copied at construction; the record is structurally immutable so it is safe to share across threads. Builder pattern is provided to avoid the 11-positional-argument constructor at call sites.
- Since:
- 0.5.0 (issue #78)
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionEventContext(String tenantId, String sessionId, String traceId, String spanId, String agentId, String agentClass, String role, List<String> capabilities, Optional<String> groupId, Optional<String> conversationId, Map<String, String> extensions) Creates an instance of aEventContextrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theagentClassrecord component.agentId()Returns the value of theagentIdrecord component.static EventContext.Builderbuilder()Returns the value of thecapabilitiesrecord component.Returns the value of theconversationIdrecord component.static EventContextempty()Empty context — used when no agent is active in the current thread.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theextensionsrecord component.groupId()Returns the value of thegroupIdrecord component.final inthashCode()Returns a hash code value for this object.role()Returns the value of therolerecord component.Returns the value of thesessionIdrecord component.spanId()Returns the value of thespanIdrecord component.tenantId()Returns the value of thetenantIdrecord component.final StringtoString()Returns a string representation of this record class.traceId()Returns the value of thetraceIdrecord component.Returns a new context with the given field overridden.
-
Constructor Details
-
EventContext
public EventContext(String tenantId, String sessionId, String traceId, String spanId, String agentId, String agentClass, String role, List<String> capabilities, Optional<String> groupId, Optional<String> conversationId, Map<String, String> extensions) Creates an instance of aEventContextrecord class.- Parameters:
tenantId- the value for thetenantIdrecord componentsessionId- the value for thesessionIdrecord componenttraceId- the value for thetraceIdrecord componentspanId- the value for thespanIdrecord componentagentId- the value for theagentIdrecord componentagentClass- the value for theagentClassrecord componentrole- the value for therolerecord componentcapabilities- the value for thecapabilitiesrecord componentgroupId- the value for thegroupIdrecord componentconversationId- the value for theconversationIdrecord componentextensions- the value for theextensionsrecord component
-
-
Method Details
-
empty
Empty context — used when no agent is active in the current thread. -
builder
-
withRole
Returns a new context with the given field overridden. Used to compose nested scopes (outer agent → inner tool, outer session → inner action). All other fields are preserved. -
withAgent
-
withGroup
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
tenantId
Returns the value of thetenantIdrecord component.- Returns:
- the value of the
tenantIdrecord component
-
sessionId
Returns the value of thesessionIdrecord component.- Returns:
- the value of the
sessionIdrecord component
-
traceId
Returns the value of thetraceIdrecord component.- Returns:
- the value of the
traceIdrecord component
-
spanId
Returns the value of thespanIdrecord component.- Returns:
- the value of the
spanIdrecord component
-
agentId
Returns the value of theagentIdrecord component.- Returns:
- the value of the
agentIdrecord component
-
agentClass
Returns the value of theagentClassrecord component.- Returns:
- the value of the
agentClassrecord component
-
role
Returns the value of therolerecord component.- Returns:
- the value of the
rolerecord component
-
capabilities
Returns the value of thecapabilitiesrecord component.- Returns:
- the value of the
capabilitiesrecord component
-
groupId
Returns the value of thegroupIdrecord component.- Returns:
- the value of the
groupIdrecord component
-
conversationId
Returns the value of theconversationIdrecord component.- Returns:
- the value of the
conversationIdrecord component
-
extensions
Returns the value of theextensionsrecord component.- Returns:
- the value of the
extensionsrecord component
-