Skip to content
Max Narditdata & ai systems
← Articles
10 mindev

LLM observability for AI agents: the trace has to show what the agent acted on, not how long the call took

A model writes no field called why, and the rationale it prints is one more thing the run says about itself. What a trace can hold is everything around the decision: what the agent saw, what it could pick, whether the call was allowed, and what it checked. The metadata for half of that is cheap to keep. The content for the other half is opt-in for good reasons.

Contents

An agent can fail with every dashboard green. It calls a tool, the call succeeds in 400 milliseconds, the token count is normal, the cost is a fraction of a cent, and it was the wrong tool. Or it reports the task done, and nothing in the run executed the step that would have made that true. Both runs look healthy on a latency-and-cost panel, because each request was healthy. The decision behind it was the problem.

A latency-and-cost dashboard measures the request. That made sense when the request was the unit of work: your code chose what to call and in what order, so the reason for each call sat in your code, and the trace only had to say whether the call went well. Anthropic’s Building effective agents draws the line that breaks this. Workflows are “orchestrated through predefined code paths”; agents are systems where the model will “dynamically direct their own processes and tool usage”. Once the model picks the next step, the reason for that step is no longer in code you can read, and the trace is the only place it can survive.

Everything below about the two telemetry exports rests on their documentation as published on November 29, 2026, not on a test run.

What LLM observability dashboards record: the call, measured from outside

The baseline is the request and its vital signs. The OpenTelemetry blog’s 2024 introduction to LLM observability lists what to capture: temperature, top_p, model name, prompt details, then tokens, cost and response details, then request volume, duration and token counters. Dashboards built on that list add error rates and percentiles. Each of those numbers answers one question: did the call behave like a healthy call?

For an agent that question misses the failure. Nothing in duration, status or token count separates a successful call to the wrong tool from a successful call to the right one. A run that skipped its test does leave a hole where the test span should be, but a hole also fits a disabled exporter, a sampler, or a delivery that failed, so the dashboard cannot tell an unverified run from an unobserved one. The request-level view is accurate about the request, which was never the thing that broke.

Why an LLM agent trace cannot record “why” directly

The obvious fix is to ask the model to explain itself and log the answer. An explanation requested after the action is a second output, not the reason for the first. Reasoning the model writes before it acts is closer to the decision, but it is still text the run produced about itself, and the rule from the watchdog post applies: a self-report is the signal you can least afford to trust on its own.

Availability is a separate problem. Claude Code’s monitoring docs say its raw API body export removes extended thinking whatever you configure:

Claude Code always redacts Claude's extended-thinking content from these
bodies, regardless of other settings.

So “why” has to be reconstructed, and what a trace can hold is everything around the decision. Two records are its inputs: what the agent could see, and what it could choose from. Two are what happened next: whether the call was allowed and by whom, and what the agent checked before calling the work finished. Together they let you test explanations against the run. They do not guarantee one: a model can choose badly on clean context, a clear menu, a sound permission and a working check, and then the trace has at least isolated the choice as the problem.

Agent trace record one: the context the LLM actually saw

The context is not the prompt you wrote. In a simple sequential loop, by the time an agent makes its tenth tool call its context holds your system instructions, the user’s request, nine tool results, whatever memory or retrieval injected, and possibly a compacted summary of an earlier stretch. Parallel calls and code that returns only part of a result change that count, and that is the point: you cannot work out what reached the model from what you configured. A wrong decision is often a correct decision on a wrong input, a stale file read, a tool result truncated before the line that mattered, a summary that dropped a constraint. Without the context, you are grading the answer without the question.

The OpenTelemetry GenAI conventions have slots for this: gen_ai.input.messages, gen_ai.output.messages and gen_ai.system_instructions. Every one is Opt-In. The two message attributes carry the warning that they are “likely to contain sensitive information including user/PII data”; the system instructions “may contain sensitive information”.

Claude Code is stricter still. Its tracing is off by default and in beta: it needs CLAUDE_CODE_ENABLE_TELEMETRY=1, CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1 and a traces exporter. With tracing on and no content flags, a request span carries the model, timing, status, ids and stop reason, but not what the model read. The full Messages API bodies come only with OTEL_LOG_RAW_API_BODIES, and the value matters. Set to 1, the bodies go out inline, truncated at 60 KB by default, so a long context can lose exactly the instruction you were looking for. Set to file:<dir>, they are written untruncated to local files and the event carries a reference. The docs’ own warning: “Bodies can include the entire conversation history.”

Agent trace record two: the tool menu, the requested call and the executed call

“Wrong tool” is a claim about a choice, and you can only judge a choice against what else was on offer at that step. The conventions call the offer gen_ai.tool.definitions, Opt-In, and they are specific about where it belongs: not combined across child agents, handoffs or steps, but recorded with each model call. The menu that matters is the one on the inference span for the decision you are investigating, next to the output in which the model asked for a tool.

There are really two calls here. The model requests a tool with arguments; the harness may refuse it, or a permission hook may change the arguments before it runs; only then does something execute. An execute_tool span describes the execution. It requires gen_ai.tool.name, carries gen_ai.tool.call.id when the model or provider supplied one, and keeps the arguments and result behind Opt-In attributes. A trace that holds only the executed call cannot tell a model that aimed at the wrong target from a hook that redirected it.

This is where a successful wrong call becomes explainable. If the menu held two tools with overlapping descriptions, that is one hypothesis, and Anthropic’s essay files the fix under the agent-computer interface. If the requested arguments were right for the context but the context was wrong, you are back at record one.

Claude Code joins its pieces with one id. Its claude_code.tool span, its tool_decision event and its tool_result event all carry the model’s tool_use_id, and the same value lands in hook payloads. On the log events, though, a user-configured MCP server’s tool appears as the literal mcp_tool, and its real server and tool names arrive only with OTEL_LOG_TOOL_DETAILS.

Agent trace record three: the permission in force and who granted it

An agent that did something it should not have done raises two questions: why did it try, and why was it allowed? The second is often the more useful one, because its answer is a rule or a mode, and those you can change today. It needs the permission state at the moment of the call and the identity of whoever decided: a static rule, a hook, a classifier or a person.

The OpenTelemetry GenAI agent and tool conventions define no attribute for a tool-authorization decision or the rule behind it. Claude Code goes further than the standard. Every tool_decision event carries decision, a source (config, hook, user_permanent, user_temporary, user_abort or user_reject) and the permission_mode in force when the check began. A classifier_verdict appears when the auto mode classifier was involved, with no_verdict or unavailable when it denied a call without a usable verdict, so a classifier outage can be told apart from a block. With OTEL_LOG_TOOL_DETAILS, classifier_category names the policy or built-in rule behind a classifier block. For everything else grouped under config, the docs mark the limit themselves:

The `source` value doesn't indicate which of these sources matched. When
`classifier_verdict` is present, it gives the classifier outcome that decided
the call. No `tool_decision` attribute names the permission rule or setting
that refused the call.

There was an event that named the kind of check. claude_code.safety_event carried a category such as permission_rule, hook or auto_mode_block. The docs now say that “v2.1.312 and later” versions “don’t send the event, and no setting turns it on”; in 2.1.307 through 2.1.311 a session stops sending it at its next feature-flag refresh. The docs point back to tool_decision, which shows “that a call was refused but not always which check refused it”.

How much of this reaches you also depends on the kind of session. When I tested denyInsteadOfPrompting for unattended sessions, a claude -p run with refused calls still exited 0 with a success subtype, but its JSON result listed them in permission_denials. An interactive or background session has no result object, so there I had to record the request with a PermissionRequest hook at the moment it happened.

Agent trace record four: the check the agent ran and what came back

“Done with nothing run” is a claim without evidence, and the trace should make the gap visible. An agent’s completion message is a report; the evidence is the tool call that ran the check and what it returned, bound to the thing the claim is about. A passing test that ran before the last edit checked a different revision. Which test ran, against which commit, with what exit code?

Claude Code records part of this. tool_result carries success, duration_ms and, on failure, an error_type; the full error text needs OTEL_LOG_TOOL_DETAILS, and so do the commit SHA and branch of a successful git commit run by the Bash tool. A refused call produces no tool_result at all. The test’s own output sits in a tool.output span event that needs tracing and OTEL_LOG_TOOL_CONTENT, is truncated past the content limit, and exists only when the tool returned successfully.

The OpenTelemetry conventions put the plainest version of the evidence on the command execution span: process.exit.code, when the tool reports a single exit code. For graded checks there is gen_ai.evaluation.result, which requires an evaluation name and takes a score, a label such as pass or fail and an explanation where applicable. It is built for an evaluator assessing a model’s output, so it records a check only if your code emits one.

The principle is the one I argued about liveness. A health signal should be a durable side effect that only the work produces, not a beat the agent sends about itself, and completion works the same way. A missing result means the claim is unverified, and the trace should say that out loud instead of staying quiet.

Where the OpenTelemetry GenAI conventions stop for agents

The GenAI conventions have left opentelemetry.io: the old pages are now a notice that they moved to their own repository, semantic-conventions-genai. The GenAI spans and gen_ai.* attributes discussed here are all at Development status.

Inside, the slots are better than the 2024 blog post suggests. There is a plan span for “an agent planning or task decomposition phase”, with a caveat: an instrumentation should emit it only “when they can reliably determine that the operation being instrumented is planning or task decomposition”, and should leave it out when planning cannot be told apart from ordinary inference. The message schema has a reasoning part for “reasoning/thinking content received from the model”, with the self-report problem above. There is no permission decision, and a deployment with default settings gets the shape of a run without its explanation.

The privacy cost of an LLM agent trace

The fields that answer why are the same ones that carry secrets. Context holds whatever the agent read, including credentials it should not have seen and client data it was right to see. Tool arguments hold file paths and commands; tool results hold file contents. Both standards make these opt-in for a reason, and “turn everything on” is a bad answer for any agent that touches real data.

The decision-side metadata is cheaper, though not free. A tool_decision event’s decision, source, mode and verdict, a tool_use_id and a success flag carry no command text. They answer whether a call was allowed and whether it succeeded. They do not name the rule, the test output still sits behind the content flags, and every Claude Code event also carries standard attributes such as user.email when available, which need filtering in the collector before export if they should not leave the machine.

For the content, the conventions define _ref variants for four fields: gen_ai.input.messages_ref, gen_ai.output.messages_ref, gen_ai.system_instructions_ref and gen_ai.tool.definitions_ref. Each holds a URI to external storage instead of the content, so the context can sit in a store with its own access control and a short retention period while the trace keeps the pointer. The spec is careful about what a pointer proves: its presence does not indicate whether storing the content succeeded, and the URI can expose bucket names and tenant identifiers. A post-mortem has to expect a dead link. I would export the decision metadata always, filter identity attributes deliberately, store the content by reference with a retention period I could defend, and turn on the rationale text last.

What an AI agent trace should hold before the first unattended run

Before an agent runs without a person watching, I would want two joins to work on metadata alone. One goes from a tool call id to the permission decision behind it, which the tool_use_id already provides. The other goes from the agent’s final claim to the checks that back it, and no export provides it for you: a final text reply carries no tool call id, so the link from “done” to a test result on the right revision is something your harness has to record. Those two say whether a wrong action was allowed and whether a finished task was checked. Whether the agent chose badly on a good input is a question for the context and the tool menu, the content you decided how long to keep. Without any of it, the post-mortem comes down to the dashboard: latency fine, tokens fine, cost fine, and no idea why the agent did it.

01 / Discussion

No comment section here — all discussions happen on X.

Max Nardit@mnardit

02 / More articles