Class: Trace
Defined in: src/lib/logger/components/trace.ts:65 Represents a trace (a single turn interaction). Traces capture the complete execution flow of operations, including generations, tool calls, retrievals, spans, and errors happening within one user interaction turn. They provide detailed timing and hierarchical organization of activities within a session or standalone operation. TraceExample
Extends
Constructors
Constructor
new Trace(Defined in: src/lib/logger/components/trace.ts:78 Creates a new trace log entry.config,writer):Trace
Parameters
config
TraceConfig
Configuration object defining the trace
writer
LogWriter
Log writer instance for persisting trace data
Returns
Trace
Example
Overrides
EventEmittingBaseContainer.constructor
Accessors
evaluate
Get Signature
get evaluate(): EvaluateContainer
Defined in: src/lib/logger/components/base.ts:248
Gets the evaluation methods for this container.
Example
Returns
EvaluateContainer
Evaluation methods for configuring and triggering evaluations
Inherited from
EventEmittingBaseContainer.evaluate
id
Get Signature
get id(): string
Defined in: src/lib/logger/components/base.ts:80
Gets the unique identifier for this container.
Returns
string
The container’s unique ID
Inherited from
EventEmittingBaseContainer.id
Methods
addAttachment()
addAttachment(Defined in: src/lib/logger/components/trace.ts:199 Adds an attachment to this trace.attachment):void
Parameters
attachment
Attachment
The attachment to add (can be of type file, data, or URL)
Returns
void
void
Example
addMetadata()
addMetadata(Defined in: src/lib/logger/components/base.ts:124 Adds metadata to this container for additional context and debugging. Any data type could be added as the value in the metadata record.metadata):void
Parameters
metadata
Record<string, unknown>
Key-value pairs of metadata
Returns
void
void
Example
Inherited from
EventEmittingBaseContainer.addMetadata
addTag()
addTag(Defined in: src/lib/logger/components/base.ts:94 Adds a tag to this container for categorization and filtering.key,value):void
Parameters
key
string
The tag key
value
string
The tag value
Returns
void
void
Example
Inherited from
EventEmittingBaseContainer.addTag
addToSession()
addToSession(Defined in: src/lib/logger/components/trace.ts:139 Associates this trace with a session.sessionId):void
Parameters
sessionId
string
The ID of the session to associate with
Returns
void
void
Example
data()
data(): any
Defined in: src/lib/logger/components/base.ts:191
Returns the current data state of this container.
Returns
any
The container’s data.
Inherited from
EventEmittingBaseContainer.data
end()
end(): void
Defined in: src/lib/logger/components/base.ts:163
Marks this container as ended and records the end timestamp.
Returns
void
void
Example
Inherited from
EventEmittingBaseContainer.end
error()
error(Defined in: src/lib/logger/components/trace.ts:265 Creates an error within this trace.config):Error
Parameters
config
ErrorConfig
Configuration for the error
Returns
Error
A new error instance associated with this trace
Example
event()
event(Defined in: src/lib/logger/components/base.ts:291 Emits a custom event within this container.id,name,tags?,metadata?):void
Parameters
id
string
Unique identifier for the event
name
string
Human-readable name for the event
tags?
Record<string, string>
Optional tags for categorizing the event
metadata?
Record<string, unknown>
Optional metadata for additional context
Returns
void
void
Example
Inherited from
EventEmittingBaseContainer.event
feedback()
feedback(Defined in: src/lib/logger/components/trace.ts:168 Adds feedback to this trace from users.feedback):void
Parameters
feedback
Feedback object containing score and optional commentcomment?
string
Optional textual feedback
score
number
Numerical score for the trace
Returns
void
void
Example
generation()
generation(Defined in: src/lib/logger/components/trace.ts:103 Creates a new generation (LLM call) within this trace.config):Generation
Parameters
config
GenerationConfig
Configuration for the generation
Returns
Generation
A new generation instance associated with this trace
Example
input()
input(Defined in: src/lib/logger/components/trace.ts:375 Sets the input for this trace.input):Trace
Parameters
input
string
The input that for this trace
Returns
Trace
This trace instance for method chaining
Example
output()
output(Defined in: src/lib/logger/components/trace.ts:402 Sets the output for this trace.output):Trace
Parameters
output
string
The final output or result of this trace execution
Returns
Trace
This trace instance for method chaining
Example
retrieval()
retrieval(Defined in: src/lib/logger/components/trace.ts:341 Creates a retrieval within this trace.config):Retrieval
Parameters
config
RetrievalConfig
Configuration for the retrieval
Returns
Retrieval
A new retrieval instance associated with this trace
Example
span()
span(Defined in: src/lib/logger/components/trace.ts:226 Creates a new span within this trace for hierarchical organization.config):Span
Parameters
config
SpanConfig
Configuration for the span
Returns
Span
A new span instance associated with this trace
Example
toolCall()
toolCall(Defined in: src/lib/logger/components/trace.ts:304 Creates a tool call within this trace.config):ToolCall
Parameters
config
ToolCallConfig
Configuration for the tool call
Returns
ToolCall
A new tool call instance associated with this trace
Example
addAttachment_()
Defined in: src/lib/logger/components/trace.ts:211 Static method to add an attachment to any trace by ID.staticaddAttachment_(writer,id,attachment):void
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
attachment
Attachment
The attachment to add
Returns
void
void
addMetadata_()
Defined in: src/lib/logger/components/base.ts:144 Static method to add metadata to any container by ID.staticaddMetadata_(writer,entity,id,metadata):void
Parameters
writer
LogWriter
The log writer instance
entity
Entity
The entity type
id
string
The container ID
metadata
Record<string, unknown>
The metadata to add
Returns
void
void
Inherited from
EventEmittingBaseContainer.addMetadata_
addTag_()
Defined in: src/lib/logger/components/base.ts:108 Static method to add a tag to any container by ID.staticaddTag_(writer,entity,id,key,value):void
Parameters
writer
LogWriter
The log writer instance
entity
Entity
The entity type
id
string
The container ID
key
string
The tag key
value
string
The tag value
Returns
void
void
Inherited from
EventEmittingBaseContainer.addTag_
addToSession_()
Defined in: src/lib/logger/components/trace.ts:151 Static method to associate any trace with a session by ID.staticaddToSession_(writer,id,sessionId):void
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
sessionId
string
The session ID to associate with
Returns
void
void
end_()
Defined in: src/lib/logger/components/base.ts:177 Static method to end any container by ID.staticend_(writer,entity,id,data?):void
Parameters
writer
LogWriter
The log writer instance
entity
Entity
The entity type
id
string
The container ID
data?
any
Optional additional data to include with the end event
Returns
void
void
Inherited from
EventEmittingBaseContainer.end_
error_()
Defined in: src/lib/logger/components/trace.ts:282 Static method to create an error associated with any trace by ID.staticerror_(writer,id,config):Error
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
config
ErrorConfig
Configuration for the error
Returns
Error
A new error instance
evaluate_()
Defined in: src/lib/logger/components/base.ts:260 Static method to get evaluation methods for any evaluatable container by ID.staticevaluate_(writer,entity,id):EvaluateContainer
Parameters
writer
LogWriter
The log writer instance
entity
Entity
The entity type
id
string
The container ID
Returns
EvaluateContainer
Evaluation methods for configuring and triggering evaluations
Inherited from
EventEmittingBaseContainer.evaluate_
event_()
Defined in: src/lib/logger/components/base.ts:318 Static method to emit an event for any event-emitting container by ID.staticevent_(writer,entity,id,eventId,name,tags?,metadata?):void
Parameters
writer
LogWriter
The log writer instance
entity
Entity
The entity type
id
string
The container ID
eventId
string
Unique identifier for the event
name
string
Human-readable name for the event
tags?
Record<string, string>
Optional tags for categorizing the event
metadata?
Record<string, unknown>
Optional metadata for additional context
Returns
void
void
Inherited from
EventEmittingBaseContainer.event_
feedback_()
Defined in: src/lib/logger/components/trace.ts:182 Static method to add feedback to any trace by ID.staticfeedback_(writer,id,feedback):void
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
feedback
Feedback objectcomment?
string
Optional textual feedback
score
number
Numerical score for the trace
Returns
void
void
generation_()
Defined in: src/lib/logger/components/trace.ts:121 Static method to create a generation associated with any trace by ID.staticgeneration_(writer,id,config):Generation
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
config
GenerationConfig
Configuration for the generation
Returns
Generation
A new generation instance
input_()
Defined in: src/lib/logger/components/trace.ts:388 Static method to set input for any trace by ID.staticinput_(writer,id,input):void
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
input
string
The input for the trace
Returns
void
void
output_()
Defined in: src/lib/logger/components/trace.ts:415 Static method to set output for any trace by ID.staticoutput_(writer,id,output):void
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
output
string
The output for the trace
Returns
void
void
retrieval_()
Defined in: src/lib/logger/components/trace.ts:358 Static method to create a retrieval associated with any trace by ID.staticretrieval_(writer,id,config):Retrieval
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
config
RetrievalConfig
Configuration for the retrieval
Returns
Retrieval
A new retrieval instance
span_()
Defined in: src/lib/logger/components/trace.ts:243 Static method to create a span associated with any trace by ID.staticspan_(writer,id,config):Span
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
config
SpanConfig
Configuration for the span
Returns
Span
A new span instance
toolCall_()
Defined in: src/lib/logger/components/trace.ts:321 Static method to create a tool call associated with any trace by ID.statictoolCall_(writer,id,config):ToolCall
Parameters
writer
LogWriter
The log writer instance
id
string
The trace ID
config
ToolCallConfig
Configuration for the tool call
Returns
ToolCall
A new tool call instance