Skip to main content

Definition

Fields

string
Unique identifier for the span. Auto-generated UUID.
string
required
ID of the parent trace.
string
ID of the parent span for nested operations.
string
required
Name describing this operation.
SpanType
required
Type of operation: LLM, CHAIN, TOOL, or FUNCTION.
dict
Input data for this operation.
dict
Output data from this operation.
string
Model name for LLM spans (e.g., "claude-sonnet-4-6").
integer
Unix timestamp in milliseconds when the span started.
integer
Unix timestamp in milliseconds when the span ended.
integer
Duration in milliseconds (end_time - start_time).
TokenUsage
Token counts for LLM spans.
dict
Additional metadata (provider, parameters, etc.).
SpanStatus
Current status: RUNNING, SUCCESS, or ERROR.
SpanError
Error information if status is ERROR.
list[string]
Tags inherited from the trace.
string
User identifier inherited from the trace.
string
Session identifier inherited from the trace.
string
Version string inherited from the trace.

SpanType Enum

SpanStatus Enum

Methods

complete()

Mark span as successfully completed:
token_usage is optional.

fail()

Mark span as failed:

Creating Custom Spans

Use the span() context manager — it handles complete() and fail() automatically:
See span() for full documentation.

JSON Serialization

See Also