Guide · Trace Analysis

Agent Tracing: What an AI Agent Trace Should Record to Show Why It Failed

The spans and attributes an AI agent trace needs, named as in the OpenTelemetry GenAI conventions and the OpenAI Agents SDK, and the failure each one exposes.

Trace Taxonomy Editors · Updated

The short answer

Agent tracing records one run of an AI agent as a tree of spans: the agent invocation at the root, and beneath it every model call, tool call, handoff and check, each with its timing, inputs, outputs and errors. A good agent trace lets you answer three questions about any run: what the agent was given, what it decided, and what it actually did.

This guide covers which spans an agent trace needs, which attributes on them expose which failure, and how the OpenTelemetry GenAI conventions and common agent frameworks name them. The failure modes it refers to are the 14 in the MAST taxonomy guide.

Traces, spans and attributes

  • Trace. One end-to-end run: a user request, a scheduled job, one task in a benchmark. Everything the run did shares its trace ID.
  • Span. One operation inside the run, with a start, an end and a parent. The parent links are what turn a list of events into the order of cause and effect.
  • Attributes.Key-value pairs on a span: the agent's name, the model, the tool and its arguments, token counts, the error. Failure checks run on attributes, so a span without them is only a timing.

An agent run differs from an ordinary request in that its shape isn't fixed in code. The model decides how many steps there are, which tools to call and when to stop, so the trace is the only record of the path a run took.

The spans an agent trace needs

Span names below are the ones the OpenTelemetry GenAI conventions recommend, next to what the OpenAI Agents SDK records by default. Other frameworks use their own names for the same operations.

OperationOpenTelemetry span nameOpenAI Agents SDKWhat it lets you see
Agent or workflow invocationinvoke_agent {agent name}, or invoke_workflow when the application defines the control flowagent_span (inside the run's trace)Which agent did the work, and the boundary of one run or sub-run. Everything below it hangs off this span.
Planplan {agent name}No dedicated span; the plan is in the generation that produced itWhat the agent decided to do before doing it, so later steps can be checked against the plan.
Model call{operation} {model}, e.g. chat gpt-4generation_spanThe prompt the model actually saw, what it returned, token counts and why it stopped.
Tool callexecute_tool {tool name}function_spanThe arguments the agent passed, the result it got back and whether the tool errored.
Handoff to another agentexecute_tool {tool name}, when the handoff is a tool call that transfers work to another agenthandoff_spanWhat one agent passed to the next, which is where context gets dropped.
Guardrail or checkNo generic GenAI span; record it as a custom spanguardrail_spanWhether a check ran at all, and what it decided.

The OpenTelemetry conventions place the model call that produces a plan under the plan span, and the tool calls that carry the plan out as its siblings under the agent span. Keeping that nesting is what lets you compare what an agent planned with what it did.

Attributes that expose failures

Each row is an attribute from the OpenTelemetry GenAI conventions, the requirement level the conventions give it, and the failure it helps you find. Where it maps to a MAST failure mode, the code links to it.

AttributeOnLevelWhat it finds
gen_ai.agent.nameAgent and plan spansWhen availableRole violations: an agent calling tools or making decisions that belong to another. (FM-1.2)
gen_ai.conversation.idAgent and model spansWhen the library has oneRuns that belong to the same session, so a failure split across several runs can be read as one.
gen_ai.tool.name and gen_ai.tool.call.idTool spansName required; call ID when the model supplies oneRepeated tool calls, and which model response asked for which tool execution. (FM-1.3)
gen_ai.tool.call.argumentsTool spansOpt-inArguments nothing upstream supplied: guessed or fabricated IDs, assumed values. (FM-2.2)
gen_ai.tool.call.resultTool spansOpt-inA fact an agent received and then left out of its handoff, or misread. (FM-2.4)
gen_ai.usage.input_tokens and output_tokensModel spansRecommendedContext that shrinks sharply between turns of the same agent. (FM-1.4)
gen_ai.response.finish_reasonsModel spansRecommendedOutputs cut off by the token limit rather than finished, which then look complete downstream.
gen_ai.input.messages and gen_ai.output.messagesModel spansOpt-inReasoning that says one thing while the tool call in the same span does another. (FM-2.6)
error.typeAny spanRequired when the operation erroredWhich errors were real errors, so they can be told apart from runs that failed with no error at all.

The conventions also ask instrumentations to set the agent name, operation name and tool name when a span starts, not when it ends, because sampling decisions are made from them. Two more things no attribute gives you: how the run ended (finished, errored, hit a turn limit, timed out) and which agent each message came from. Add both yourself if your framework doesn't record them.

Recording prompts and tool results

In the OpenTelemetry conventions the content attributes are opt-in: the messages sent to and from the model, the system instructions, tool definitions, tool arguments and tool results. The conventions warn that tool arguments and results may contain sensitive information.

Leaving content out keeps a trace safe, but it also hides most agent failures. A fabricated order ID, a constraint the agent dropped or a fact it never passed on all look like a normal tool call when you only have names and timings. Ways to keep the content without spreading it:

  • Store content elsewhere and link to it. The conventions define _ref attributes (for example gen_ai.input.messages_ref) that hold a URI to the content in separate storage, so the trace backend never holds it.
  • Redact before export. Strip or hash personal data in a processor before spans leave the process.
  • Keep identifiers even when you drop text. Tool names, call IDs and the IDs inside arguments are usually enough to check whether a value had a source.

What traces show that logs and metrics don't

An agent can return a success status, stay within its latency budget and still do the wrong thing. Metrics count those runs as healthy, and logs show each step on its own. A trace keeps the steps in order with their parents, which is what you need to find the first step that went wrong rather than the last step that showed it. Silent success codes masking agent misbehavior and Root-cause attribution across parallel agent spans go further into both.

Tracing in agent frameworks

OpenAI Agents SDK

Tracing is built in and on by default. Each run is wrapped in a trace, with spans for agents, LLM generations, function tool calls, guardrails and handoffs. Traces have a workflow name and an optional group ID that links traces from the same conversation. Custom trace processors can send them to other destinations as well as, or instead of, OpenAI's Traces dashboard. The SDK's docs note that tracing is unavailable for organizations using OpenAI's APIs under a Zero Data Retention policy. See its tracing docs.

Frameworks with OpenTelemetry instrumentation

The OpenTelemetry conventions name LangChain, LangGraph, CrewAI, Microsoft Agent Framework, Pydantic AI, Google's ADK and the OpenAI Agents SDK in their guidance on which operations count as agents and which as workflows. Whether a given framework emits these spans, and which version of the conventions it follows, depends on its instrumentation: check the framework's own docs.

Vercel AI SDK

The AI SDK emits OpenTelemetry spans for its calls and records inputs and outputs unless you turn that off. Its telemetry docs list the spans and options. Trace-driven debugging for Vercel AI SDK agents walks through reading them.

Checklist before you trust your traces

  1. One trace per run. Every span of a run, including sub-agents and remote agents, shares its trace ID.
  2. Every span names its agent.Without it, inter-agent failures can't be told apart.
  3. Tool spans carry arguments and results, stored or linked in a way your privacy rules allow.
  4. Model spans carry token counts and finish reasons.
  5. Every run records how it ended. Finished, errored, turn limit or timeout.
  6. Whole runs are kept. Sample runs, never spans out of a run. Why sampling destroys pattern visibility explains why.
  7. Checks run on the attributes. Start with the deterministic ones in Reading multi-step agent traces without an LLM judge, then group what they find across runs.

FAQ

What is agent tracing?

Agent tracing is recording every step of an AI agent's run as a tree of timed spans: the agent invocation at the root, and under it each model call, tool call, handoff and check, with their inputs, outputs and errors. One trace is one run, so you can read back what the agent saw, decided and did, in order.

How is agent tracing different from LLM tracing?

LLM tracing usually records single model calls. Agent tracing records the run around them: which agent made each call, the tools it used with what arguments, what it handed to other agents and how the run ended. Most agent failures sit in those steps, not inside one model call.

Is there a standard for agent traces?

OpenTelemetry's semantic conventions for generative AI define span names and attributes for agent invocations, model calls and tool executions. They are still marked as in development and now live in their own repository, so check the current version before you build on a specific attribute.

Should a trace record prompts and tool results?

Several failure modes can only be seen in content: fabricated arguments, withheld information, reasoning that contradicts the action. The OpenTelemetry conventions make content opt-in because it can hold sensitive data. Record it where you can redact it or keep it in separate storage, rather than not at all.

Should agent traces be sampled?

Not span by span. Failures like step repetition, conversation resets and early termination only show across a whole run, so if you sample, keep or drop entire runs.

Sources