Span represents a single operation within an agent execution. Spans form a parent-child hierarchy within a trace, allowing you to understand the execution flow.
Span Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
span_id | str | Required | Unique span identifier |
trace_id | str | Required | Parent trace ID (groups related spans) |
parent_span_id | Optional[str] | None | Parent span ID (None for root spans) |
name | str | Required | Operation name (e.g., OpenAIChat.invoke, get_weather) |
status_code | str | Required | Status: OK, ERROR, or UNSET |
status_message | Optional[str] | None | Status message (typically error details) |
duration_ms | int | Required | Execution time in milliseconds |
start_time | datetime | Required | When the span started |
end_time | datetime | Required | When the span completed |
attributes | Optional[dict] | None | OpenTelemetry attributes (tokens, params, etc.) |
events | Optional[list] | None | Span events |
kind | Optional[str] | None | Span kind (e.g., INTERNAL, CLIENT) |
Common Span Names
Spans are automatically created for various operations:| Span Name Pattern | Description |
|---|---|
{AgentName}.run | Agent execution |
{TeamName}.run | Team execution |
{ModelName}.invoke | LLM model call |
{tool_name} | Tool execution |
Attributes by Operation Type
Theattributes field contains OpenTelemetry semantic attributes that vary by operation:
LLM Spans
| Attribute | Description |
|---|---|
llm.token_count.prompt | Input token count |
llm.token_count.completion | Output token count |
llm.model_name | Model identifier |
llm.provider | Model provider name |
Tool Spans
| Attribute | Description |
|---|---|
tool.name | Tool function name |
tool.parameters | Tool input parameters (JSON) |
Methods
to_dict()
Convert the span to a dictionary.
dict
from_dict()
Create a span from a dictionary.
data(dict): Dictionary containing span data
Span
Usage
Building a Span Tree
See Also
- Trace Reference - Complete execution trace
- DB Functions - Query functions for traces and spans