Span Class
TheSpan class represents a specific operation within a trace. Spans are the building blocks of observability, tracking individual steps like LLM calls, tool executions, database queries, or any custom operation in your LLM pipeline.
Overview
A span captures:- Operation details: name, timing, status
- Content: input/output data for different span types (Model, Tool, Retrieval, etc.)
- Metadata: tags, attributes for filtering and analysis
- Hierarchy: parent-child relationships for nested operations
- Evaluation: optional evaluator execution
- Model - LLM inference calls
- ModelStream - Streaming LLM responses
- Tool - Function/API executions
- Retrieval - RAG and vector searches
- Embeddings - Embedding generation
- Function - Custom application logic
- Guardrail - Safety/compliance checks
- Other - Any custom operation
Creation
Create spans from a trace or parent span:Properties
span
Methods
logSpan()
Create a nested child span under this span.Parameters
Same parameters as
Trace.logSpan(). See Trace.logSpan() for details.Returns
A new child Span instance linked to this parent span.
Example
update()
Update span metadata and content.Parameters
Returns
Returnsthis for method chaining.
Examples
end()
Mark the span as complete and ready to be flushed.Behavior
- Sets
endedAttimestamp - Marks the span as
readyin the monitor’s buffer - Recursively ends all child spans
- Returns the span’s reference ID
Returns
The span’s reference ID for correlation.
Example
Span Content Types
Different content types for different operations. See LogSpanContent Type for complete documentation.Model (LLM Inference)
For standard LLM completions (LogSpanModelContent).The
variables field is typed as LogSpanVariable | null in the SDK. LogSpanVariable is a record type, so you can pass a plain object as shown above.