TraceEvent

org.llm4s.trace.TraceEvent
See theTraceEvent companion object
@Stable
sealed trait TraceEvent

Type-safe, sealed hierarchy of trace events emitted during LLM agent execution.

Each subtype carries the data relevant to one observable moment in the agent lifecycle (completion received, tool executed, token usage recorded, etc.). All subtypes are serialisable to JSON via toJson, which produces a flat object containing at minimum "event_type" and "timestamp" fields.

== Error truncation == ErrorOccurred.toJson includes only the first 5 frames of the stack trace to limit payload size.

== Timestamp default == Every event's companion apply defaults timestamp to Instant.now() at construction time. Override explicitly when replaying historical events or writing deterministic tests.

== Growth safety == Each event is a final case class with a private constructor and copy: build one with its companion apply and change a field with its with* setter (an Option field's setter takes the value or an Option), so a field can be added later without breaking binary compatibility.

Attributes

See also

Tracing for the interface that consumes these events

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def eventType: String
def timestamp: Instant
def toJson: Value

Concrete methods

def span: Option[TraceSpan]

Where this event sits in a trace, when its emitter places it in one (design 4.58): the span it is, that span's parent and when it started; the event's timestamp is its end. None for an event traced on its own. Only TraceEvent.CustomEvent, TraceEvent.TokenUsageRecorded, TraceEvent.ErrorOccurred and TraceEvent.AgentRunEnded carry one.

Where this event sits in a trace, when its emitter places it in one (design 4.58): the span it is, that span's parent and when it started; the event's timestamp is its end. None for an event traced on its own. Only TraceEvent.CustomEvent, TraceEvent.TokenUsageRecorded, TraceEvent.ErrorOccurred and TraceEvent.AgentRunEnded carry one.

Attributes