The short answer
AI agent tracing records each run of an agent as a tree of timed steps called spans: one root span for the run, with child spans for each model call, tool call, retrieval, handoff and human request. Each span has a start, an end, a status and attributes like model name, token counts or tool name.
Traces answer "what happened in this run, in what order, and how long did each step take". OpenTelemetry's GenAI semantic conventions give common names for these spans, such as invoke_agent, chat and execute_tool, so traces from different frameworks look alike.

"ai agent tracing" gets about 70 US searches a month at a keyword difficulty of 16 (Semrush, November 2026). Low difficulty and high intent: the searchers are instrumenting something this week.
Anatomy of an agent trace
trace_id 4bf92f3577b34da6
invoke_agent "triage-agent" status=OK 31.2s
├── chat model=claude-sonnet in=2,140 out=310 4.1s
├── execute_tool "search_tickets" call_id=t1 0.8s
├── chat model=claude-sonnet in=3,870 out=220 3.2s
├── execute_tool "get_customer" call_id=t2 0.3s
├── execute_tool "update_ticket" call_id=t3 status=ERROR 0.2s
│ └── http PATCH /tickets/8812 403
├── chat model=claude-sonnet in=4,410 out=180 2.9s
└── execute_tool "post_comment" call_id=t4 0.5s
Reading it: the agent searched, looked up the customer, failed to update the ticket because of a permission error, then posted a comment instead. Without the trace, you'd see only the final comment.
OpenTelemetry GenAI names
| Operation | Span name pattern | Useful attributes |
|---|---|---|
| Agent run | invoke_agent {agent name} |
gen_ai.agent.name, gen_ai.agent.id, version |
| Model call | chat {model} |
gen_ai.request.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens |
| Tool call | execute_tool {tool name} |
gen_ai.tool.name, gen_ai.tool.call.id |
| Agent creation | create_agent {agent name} |
agent attributes |
| Workflow | invoke_workflow |
workflow name |
In June 2026 the GenAI conventions moved into their own repository so they can change faster, and they're still marked as in development. Pin the version your instrumentation follows, and expect attribute names to shift.
Instrumenting a run
Most frameworks have integrations that create these spans for you. For custom loops, a few lines with the OpenTelemetry SDK:
from opentelemetry import trace
tracer = trace.get_tracer("triage")
def run_agent(task):
with tracer.start_as_current_span("invoke_agent triage-agent") as run:
run.set_attribute("gen_ai.agent.name", "triage-agent")
run.set_attribute("app.task_id", task.id)
while not done:
with tracer.start_as_current_span("chat claude-sonnet") as s:
resp = model.call(messages)
s.set_attribute("gen_ai.usage.input_tokens", resp.usage.input)
s.set_attribute("gen_ai.usage.output_tokens", resp.usage.output)
for call in resp.tool_calls:
with tracer.start_as_current_span(f"execute_tool {call.name}") as t:
t.set_attribute("gen_ai.tool.name", call.name)
t.set_attribute("gen_ai.tool.call.id", call.id)
result = tools[call.name](**call.args)
Propagating context
A trace is only complete if every part of the run joins it:
- Tool calls over HTTP: inject trace headers (W3C
traceparent) so the tool's own spans attach as children. - Handoffs between agents: pass the trace context with the handoff message.
- Queues and background jobs: put the context in message metadata.
- MCP servers: pass context where the transport allows, or link spans by IDs.
Broken propagation shows up as many tiny disconnected traces instead of one tree.
Human requests as spans
When an agent waits for a person, record it:
| Attribute | Example |
|---|---|
| Request type | approval |
| Assignee | on-call-platform |
| Wait time | 312 seconds |
| Decision | approve |
Then you can separate machine time from human time in every trace.
What to capture, and what not to
| Capture | Be careful with |
|---|---|
| Model, tokens, latency, status | Full prompts and completions |
| Tool names, call IDs, durations | Tool arguments containing personal data |
| Agent name, version, task ID | Secrets passed to tools |
| Errors and retries | Documents retrieved for context |
Record content in development; in production, redact or sample it.
Sampling
Agents generate many spans. A common policy: keep 100% of errors and slow runs, 10 to 20% of normal successes, and all runs for new agent versions for their first days. Tail-based sampling in an OpenTelemetry collector can decide after a trace finishes, so you don't drop the interesting ones.
Trace retention
Traces are bulky. Keep full traces for a few weeks, long enough to debug recent issues and compare with the previous release. Keep summaries, such as status, duration, cost and outcome per run, much longer for trends.
Reading traces well
- Start at the root status, then find the first non-OK span.
- Look at durations: the longest span is often the story.
- Check token growth across chat spans; rising input tokens show context bloat.
- Compare with a good run of the same task.
- Follow actions out of the trace into the systems they changed.
Traces for coding agents
Coding agents like Claude Code and Codex run as products rather than code you instrument. They offer telemetry exports and hooks instead: Claude Code can send OpenTelemetry metrics and events, and both tools can run commands on events such as a finished turn or a permission prompt. Use those to create spans or events for the moments that matter to you, such as session start, tool approvals and completion, and send them to the same backend as your other agents.
Linking traces to business objects
A trace ID means nothing to a support lead. Put the IDs people use on the root span: ticket number, order ID, pull request number, customer account. Then anyone can go from "what happened to ticket 8812" to the exact run, and from a run to the record it changed.
Where to send traces
Langfuse, LangSmith, Arize Phoenix, Braintrust, AgentOps, Datadog and Grafana Tempo all accept agent traces, many through OpenTelemetry. Pick by what else you need: evaluations, prompt management, existing monitoring or self-hosting. See AI agent observability tools.
A worked example
Picture a triage agent that started leaving comments instead of updating tickets. Nobody noticed for a week, because the agent never failed. A trace shows update_ticket returning 403 since a token rotation, and the agent adapting by commenting. The team fixes the token's scope and adds an alert on execute_tool error rates per tool. Next time, they know within the hour.
Key takeaways
- An agent trace is a tree of spans: run, model calls, tool calls, handoffs, human requests.
- OpenTelemetry GenAI conventions name these spans but are still evolving.
- Propagate context through tools, handoffs and queues to keep one tree per run.
- Sample wisely: keep errors and slow runs, redact content in production.
FAQ
What is AI agent tracing?
Recording each agent run as a tree of timed spans for model calls, tool calls and other steps, so you can see what happened and why.
What is the difference between a trace and a span?
A span is one timed step; a trace is the full tree of spans for one run, linked by a trace ID.
Does OpenTelemetry support AI agents?
Yes. Its GenAI semantic conventions define spans for agent runs, model calls and tool execution, though they're still in development.
Should traces include prompts?
In development, yes. In production, consider redacting or sampling content because of cost and privacy.
Where Tapnod fits
Traces explain a run after the fact; Tapnod tells you in the moment when an agent needs you, finishes or fails. Start free.