Spans
Individual operations within a trace.
Spans represent individual operations within a trace, forming a tree structure.
Span Kinds
Every span has a kind field indicating its role. These are the 17 SpanKind values:
Standard Kinds
| Kind | Description | Auto-Created |
|---|---|---|
internal | Default, internal operation | - |
server | Server-side of RPC | - |
client | Client-side of RPC | - |
producer | Message producer | - |
consumer | Message consumer | - |
Agent-Specific Kinds
| Kind | Description | Auto-Created |
|---|---|---|
agent | Agent lifecycle span | @agent decorator |
llm_call | LLM API call | Yes (auto-instrumented) |
tool_call | Tool/function execution | Python: @trace_act, or @trace(kind=SpanKind.TOOL_CALL) on your tool function. JavaScript: traceAct(), or getTracer().startSpan({ name, kind: SpanKind.TOOL_CALL }, fn). Some framework integrations make it too. See Trace your own tool function (Python) and in JavaScript |
retrieval | RAG retrieval operation | Yes (framework integration) |
decision | Agent decision point (generic) | Manual |
delegation | Delegation to another agent | @trace_delegate decorator |
coordination | Multi-agent coordination | @trace_coordinate decorator |
message | Inter-agent message | @trace_message decorator |
Phase-Specific Kinds
| Kind | Description | Auto-Created |
|---|---|---|
think | Reasoning/planning phase | @trace_think decorator |
decide | Decision-making phase | @trace_decide decorator |
observe | Environment observation phase | @trace_observe decorator |
reflect | Self-evaluation phase | Manual |
SpanKind vs SemanticPhase
There is no SpanKind.ACT. The @trace_act decorator uses SpanKind.TOOL_CALL for the span kind and sets SemanticPhase.ACT as context metadata. SemanticPhase is a separate enum with 7 values: THINK, DECIDE, ACT, REFLECT, OBSERVE, COMMUNICATE, COORDINATE.
Span Attributes
Common Attributes
| Attribute | Type | Description |
|---|---|---|
span_id | string | Unique 16-char hex ID |
trace_id | string | Parent trace ID (32-char hex) |
parent_span_id | string | Parent span ID |
name | string | Span name |
kind | string | Kind from the tables above |
start_time | timestamp | Start time |
end_time | timestamp | End time |
duration_ms | number | Duration in milliseconds |
status | string | unset, ok, or error |
LLM Span Attributes
| Attribute | Description |
|---|---|
gen_ai.system | Provider (openai, anthropic, google, etc.) |
gen_ai.request.model | Requested model name |
gen_ai.response.model | Model name returned by API |
gen_ai.response.id | Response ID |
gen_ai.usage.prompt_tokens | Input tokens |
gen_ai.usage.completion_tokens | Output tokens |
gen_ai.usage.total_tokens | Total tokens |
gen_ai.request.temperature | Sampling temperature |
gen_ai.request.max_tokens | Max output tokens |
gen_ai.request.top_p | top_p of the request, when set. OpenAI and Anthropic patches. Sent with content capture on or off |
gen_ai.request.tool_choice | tool_choice of the request, when set. OpenAI and Anthropic patches. Sent with content capture on or off |
gen_ai.request.stop_sequences | Stop sequences of the request (the stop of OpenAI), when set. OpenAI and Anthropic patches. Sent with content capture on or off |
gen_ai.request.seed | seed of the request, when set. OpenAI patch only. Sent with content capture on or off |
gen_ai.request.stream | Whether streaming was used |
gen_ai.request.has_tools | Whether tools were provided |
gen_ai.usage.cache_read.input_tokens | Input tokens that the provider read from its prompt cache, when the response gives them (OpenAI, Anthropic, LiteLLM) |
gen_ai.usage.cache_write.input_tokens | Input tokens that the provider wrote to its prompt cache, when the response gives them (OpenAI, Anthropic, LiteLLM) |
gen_ai.usage.reasoning.output_tokens | Output tokens that the model used for reasoning, when the response gives them (OpenAI, Anthropic, LiteLLM) |
gen_ai.tool.definitions | The tools of the request in one flat form, at most 24,576 bytes. OpenAI and Anthropic patches, with content capture on |
gen_ai.system_instructions | The Anthropic system prompt, kept whole, at most 16,384 bytes. Anthropic patch, with content capture on |
gen_ai.input.messages | The whole messages list in the OpenTelemetry parts form, at most 49,152 bytes by default (max_input_messages_bytes). OpenAI and Anthropic patches, with content capture on |
risicare.prompt.name, risicare.prompt.version, risicare.prompt.hash, risicare.prompt.label | The prompt that the messages came from, when they came from a pulled prompt or a prompt_context block. Sent with content capture on or off |
gen_ai.completion.tool_calls | Number of tool calls |
gen_ai.completion.tool_call.{j}.name | Name of tool call j (the first 5). OpenAI patch |
gen_ai.completion.tool_uses | Number of tool use blocks. Anthropic patch |
gen_ai.completion.tool_use.{j}.name | Name of tool use block j (the first 5). Anthropic patch |
gen_ai.completion.0.tool_calls.{j}.arguments | Arguments of tool call j (OpenAI), or the input of tool use block j (Anthropic), as JSON text. The first 5, each cut at 10,000 characters. OpenAI and Anthropic patches, with content capture on |
gen_ai.completion.finish_reason | Stop reason |
gen_ai.response.stop_reason | Stop reason. Anthropic patch |
gen_ai.latency_ms | Request latency in milliseconds (set by the provider instrumentation; the span's overall duration_ms also carries timing) |
The cache and reasoning counts and the request parameters are not content: trace_content=False keeps them. The number and the names of tool calls and the finish or stop reason are not content either: the SDK sends them with capture on or off. The keys for tool definitions, system instructions, input messages and the arguments of tool calls are content: they appear only with content capture on, which is the default since Python 0.7.0 and npm 0.10.0. A streamed answer records its tool calls with the same keys as an answer that is not a stream. See OpenAI and Anthropic.
Tool Span Attributes
| Attribute | Description |
|---|---|
tool.name | Tool name |
tool.input | Tool input (JSON) |
tool.output | Tool output (JSON) |
tool.error | Error message if failed |
The decorators @trace and @trace_act set none of these keys. Some framework integrations set some of them. For your own tool function, set tool.input and tool.output yourself. tool.input and tool.output are content: with trace_content=False, the SDK replaces them with <risicare:content-omitted>.
Agent Span Attributes
| Attribute | Description |
|---|---|
agent.name | Agent name |
agent.role | Agent role |
agent.id | Unique agent instance ID |
agent.parent_id | Parent agent ID |
agent.iteration | Loop iteration number |
Span Hierarchy
Spans form a tree rooted at the trace:
# This code creates:
# Trace
# └── Agent Span (orchestrator) [kind: agent]
# ├── Think Span [kind: think]
# │ └── LLM Span [kind: llm_call]
# ├── Decide Span [kind: decide]
# │ └── LLM Span [kind: llm_call]
# └── Act Span [kind: tool_call]
# └── Tool Span [kind: tool_call]
@agent(name="orchestrator")
def run():
@trace_think
def think():
return llm.generate("Analyze...")
@trace_decide
def decide():
return llm.generate("Plan...")
@trace_act
def act():
return tool.execute()
think()
decide()
act()Error Spans
When an operation fails:
{
"span_id": "abc123def4567890",
"kind": "llm_call",
"status": "error",
"error": {
"type": "ToolExecutionError",
"message": "API timeout after 30s",
"code": "TOOL.EXECUTION.TIMEOUT",
"stack_trace": "..."
}
}Custom Spans
Create custom spans for any operation:
from risicare import get_tracer
def process_data():
tracer = get_tracer()
with tracer.start_span(
"data_processing",
attributes={"batch_size": 100},
) as span:
result = do_processing()
span.set_attribute("records", len(result))
return resultSpan Events
Add events within a span:
from risicare import get_tracer
tracer = get_tracer()
with tracer.start_span("pipeline") as span:
span.add_event("stage_1_complete", {"records": 100})
process_stage_1()
span.add_event("stage_2_complete", {"records": 95})
process_stage_2()Performance Analysis
Parallel Execution
Spans at the same level with overlapping times indicate parallel execution.
Bottlenecks
The waterfall orders spans by start time, and you can expand and collapse the children of a span. It has no sort by duration and no filter by kind.