Topic 1 of 5 · 5 min read
Traces and spans across many agents
Goal: Read a multi-agent trace tree and say which agent, step and tool call produced a given output.
A trace is the full record of one run, and each span inside it is one timed step, nested under the step that started it. In a multi-agent system the nesting is what tells you who did what.
Check yourself · 1 of 3
In a trace of a multi-agent run, what does a span's parent link tell you?
Why it matters
A single agent leaves one chain of calls. A lead agent that briefs three workers leaves a tree. When the final answer is wrong, logs from five agents interleave and nobody can say which line belongs to which run. A trace gives every step a trace id (the run) and a parent id (who called it), so the tree can be rebuilt.
The shape to expect
- Root span: the whole run, for example
run: refund-request-8841. - Agent spans: one per agent invocation, children of the root or of the agent that delegated.
- Generation spans: one per model call, with the prompt, the reply, token counts and latency.
- Tool spans: one per tool call, with arguments, result and any error.
- Handoff or delegate spans: the moment one agent passes work to another.
Each span carries a start time, a duration, a status and attributes such as the agent name and model.
How to read one
- Find the root and the final output. Then read down, not across.
- For each agent span, note its input (the brief it got) and its output.
- Open the generation span under it to see what the model was actually shown.
- Open the tool spans to see what came back from the world.
- Compare the time bars. A long gap with no child span often means a retry, a queue or code outside the trace.
Before and after
Before: a log file with lines like worker: done, lead: merging, from three concurrent runs. After:
run: refund-request-8841 4.2s ok
agent: lead (planner) 4.1s ok
generation: plan 0.9s ok
agent: worker-orders 1.1s ok
tool: orders.lookup(id=8841) 0.2s ok
agent: worker-policy 1.4s ok
tool: policy.search("refund 30 days") 0.3s ok
generation: final answer 0.8s ok
Now the question "where did the refund window come from?" has an answer: worker-policy, tool policy.search.
What goes wrong
- Broken parent links. If the lead does not pass trace context to a worker (a separate process, a queue), the worker's spans appear as a second, unrelated trace.
- Spans that are too coarse. One span called
agenthides the model call and the tool call inside it. - Spans that are too fine. Every string operation becomes a span and the tree is unreadable.
- Reading the root status as the truth. A root marked
okonly means nothing threw. The answer can still be wrong.
Examples
Finding the source of a number
The final answer says refunds are allowed for 60 days. In the trace, worker-policy called policy.search, and the tool span result contains a page titled Refund policy (2023, archived) with the 60-day line. The wrong figure came from a stale document returned by a tool, not from the lead agent's reasoning.
An orphan worker
trace a1f3 run: refund-request-8841 (lead, 3 children)
trace 77c0 agent: worker-orders (no parent)
The orders worker runs in a queue consumer and never received the trace context. Fix it by putting the trace id and parent span id in the job payload and starting the worker span from them.
Key points
- A trace is one run; a span is one timed step with a parent, so the tree shows who called whom.
- Expect agent, generation, tool and handoff spans, each with timing, status and attributes.
- Read down the tree from the final output: agent input, model call, then tool results.
- Trace context must be passed across processes and queues, or workers become orphan traces.
- A span status of ok means no exception was raised, not that the output was correct.
Common mistakes
- Logging each agent separately with no shared run id, then trying to join lines by timestamp.
- Recording only the agent span and not the model and tool calls beneath it.
- Treating an ok status on the root span as proof that the answer was right.
- Forgetting to propagate trace context when a worker runs in another process or job queue.
Check yourself · 2 of 3
A worker agent runs in a queue consumer and shows up as a separate trace with no parent. What is the most likely cause?
Check yourself · 3 of 3
The root span of a run is marked ok, yet the customer got a wrong refund window. What should you do next?
Practice items, not counted towards your mastery.
Start here
- OpenTelemetry semantic conventions for MCP (GenAI repository) (opens in a new tab)ToolFree
The agreed attribute names for model calls, token counts and agent spans.
- AI agent observability (OpenTelemetry blog) (opens in a new tab)ArticleFree
Why agents need tracing and how the community is standardising it.
- Tracing (OpenAI Agents SDK docs) (opens in a new tab)DocsFree
Built-in traces, spans, handoffs and how to switch off sensitive data capture.
More for this topic
- Traces (OpenTelemetry) (opens in a new tab)DocsFree
Defines traces, spans, parent-child links and span attributes.