Skip to main content

Spans

Individual operations within a trace.

Spans represent individual operations within a trace, forming a tree structure.

Span Kinds

17 SpanKind values organized into Standard OTel, Agent Operations, and Cognitive Phases categories

Every span has a kind field indicating its role. These are the 17 SpanKind values:

Standard Kinds

KindDescriptionAuto-Created
internalDefault, internal operation-
serverServer-side of RPC-
clientClient-side of RPC-
producerMessage producer-
consumerMessage consumer-

Agent-Specific Kinds

KindDescriptionAuto-Created
agentAgent lifecycle span@agent decorator
llm_callLLM API callYes (auto-instrumented)
tool_callTool/function executionPython: @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
retrievalRAG retrieval operationYes (framework integration)
decisionAgent decision point (generic)Manual
delegationDelegation to another agent@trace_delegate decorator
coordinationMulti-agent coordination@trace_coordinate decorator
messageInter-agent message@trace_message decorator

Phase-Specific Kinds

KindDescriptionAuto-Created
thinkReasoning/planning phase@trace_think decorator
decideDecision-making phase@trace_decide decorator
observeEnvironment observation phase@trace_observe decorator
reflectSelf-evaluation phaseManual

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

AttributeTypeDescription
span_idstringUnique 16-char hex ID
trace_idstringParent trace ID (32-char hex)
parent_span_idstringParent span ID
namestringSpan name
kindstringKind from the tables above
start_timetimestampStart time
end_timetimestampEnd time
duration_msnumberDuration in milliseconds
statusstringunset, ok, or error

LLM Span Attributes

AttributeDescription
gen_ai.systemProvider (openai, anthropic, google, etc.)
gen_ai.request.modelRequested model name
gen_ai.response.modelModel name returned by API
gen_ai.response.idResponse ID
gen_ai.usage.prompt_tokensInput tokens
gen_ai.usage.completion_tokensOutput tokens
gen_ai.usage.total_tokensTotal tokens
gen_ai.request.temperatureSampling temperature
gen_ai.request.max_tokensMax output tokens
gen_ai.request.top_ptop_p of the request, when set. OpenAI and Anthropic patches. Sent with content capture on or off
gen_ai.request.tool_choicetool_choice of the request, when set. OpenAI and Anthropic patches. Sent with content capture on or off
gen_ai.request.stop_sequencesStop sequences of the request (the stop of OpenAI), when set. OpenAI and Anthropic patches. Sent with content capture on or off
gen_ai.request.seedseed of the request, when set. OpenAI patch only. Sent with content capture on or off
gen_ai.request.streamWhether streaming was used
gen_ai.request.has_toolsWhether tools were provided
gen_ai.usage.cache_read.input_tokensInput tokens that the provider read from its prompt cache, when the response gives them (OpenAI, Anthropic, LiteLLM)
gen_ai.usage.cache_write.input_tokensInput tokens that the provider wrote to its prompt cache, when the response gives them (OpenAI, Anthropic, LiteLLM)
gen_ai.usage.reasoning.output_tokensOutput tokens that the model used for reasoning, when the response gives them (OpenAI, Anthropic, LiteLLM)
gen_ai.tool.definitionsThe tools of the request in one flat form, at most 24,576 bytes. OpenAI and Anthropic patches, with content capture on
gen_ai.system_instructionsThe Anthropic system prompt, kept whole, at most 16,384 bytes. Anthropic patch, with content capture on
gen_ai.input.messagesThe 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.labelThe 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_callsNumber of tool calls
gen_ai.completion.tool_call.{j}.nameName of tool call j (the first 5). OpenAI patch
gen_ai.completion.tool_usesNumber of tool use blocks. Anthropic patch
gen_ai.completion.tool_use.{j}.nameName of tool use block j (the first 5). Anthropic patch
gen_ai.completion.0.tool_calls.{j}.argumentsArguments 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_reasonStop reason
gen_ai.response.stop_reasonStop reason. Anthropic patch
gen_ai.latency_msRequest 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

AttributeDescription
tool.nameTool name
tool.inputTool input (JSON)
tool.outputTool output (JSON)
tool.errorError 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

AttributeDescription
agent.nameAgent name
agent.roleAgent role
agent.idUnique agent instance ID
agent.parent_idParent agent ID
agent.iterationLoop 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 result

Span 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.

Next Steps