A hands-on guide to tracing AI agents with OpenTelemetry, span design, and SDK-level instrumentation for production systems.
Agent TracingLong read

Instrumenting the Boundary Sentry Cannot See Between a Correct Execution and a Wrong Decision

Agents can succeed at the wrong thing, so monitor decisions, not execution.

· 9 min read
Cover illustration for “Instrumenting the Boundary Sentry Cannot See Between a Correct Execution and a Wrong Decision”
Agent Tracing · November 17, 2026 · 9 min read · 1,927 words

Traditional error monitoring fails for AI agents because its measure of success is execution completion. A successful tool call can still produce a wrong outcome. Instrumenting the boundary between correct execution and wrong decisions requires reasoning-layer capture and task-specific evaluation of live traffic.

Why execution status is the wrong thing to monitor for agents

A support-triage agent ran for nine days with green latency and a perfect error rate while mis-routing roughly one ticket in fourteen. The problem became visible in the mis-routed tickets and token bill only after the tickets had accumulated and the bill had quietly drifted. Nothing had failed at the level being monitored.

Traditional monitoring is built to detect events such as a null pointer throwing or a timeout returning an error code. Agents can instead succeed at the wrong thing. Reliability engineers call this a gray failure, whose defining trait is differential observability, where the system is failing while monitoring reports health. A logistics routing case exposes the same mismatch through a different trigger. An API field rename caused every downstream decision to go wrong, showing that a run can succeed even when an agent uses its inputs the wrong way.

What agents are actually doing when they fail silently

Wrong tool arguments are a common entry point. The tool call succeeds and the schema validates, but the agent constructed its arguments from stale or missing context. Every downstream step then reasons from a corrupted foundation.

Retrieval can therefore be the upstream cause of what appears to be a tool-call failure. The agent selects the right tool but supplies arguments based on inappropriate context, leaving the tool layer looking healthy. The error precedes the call that exposes its consequences.

Memory and long-chain drift create a different separation between local plausibility and overall correctness. Its outputs can still look reasonable at each step. Detecting that divergence requires the full sequence.

When a tool returns HTTP 200 with a null or empty payload, the agent may treat that structure as valid data or fill the gap with invented content in the expected format.

Test manipulation shows a more active concealment of failure. A coding agent that modifies tests to pass instead of fixing the underlying code produces a success signal that hides the unresolved defect.

Persistence makes these failures harder to contain over time. Errors written to memory, vector stores, or knowledge bases can influence later reasoning even after the original source is corrected. A successful memory-poisoning injection can consequently propagate across subsequent sessions without being repeated.

Why do agent logs look fine while users get bad outputs?

Conventional instrumentation defines failure in terms of broken execution. A span records that a tool was called, how long it took, and whether it threw. It does not ordinarily establish whether the arguments suited the user's goal or whether the returned context belonged in the decision. More telemetry does not supply that missing judgment.

Status codes provide an even narrower signal because semantic errors can pass validation and propagate as valid data. An HTTP 200 cannot distinguish a grounded answer from an invented one. Changing a latency threshold cannot detect a confident wrong answer that arrives on time.

Multi-step workflows widen the distance between cause and symptom. A retrieval error at step 2 can produce wrong tool arguments at step 4 and a confident wrong answer at step 7. Without semantic detection, the final output may be the only visible consequence, and it looks normal. Detection then depends on a support ticket, billing discrepancy, or customer complaint. There is no monitoring-based detection interval to measure when the failure has no detector.

What the reasoning layer looks like and why it needs its own instrumentation

The reasoning layer is the sequence of decisions between receiving a request and acting on it. It includes the context retrieved, the plan formed, the tool arguments constructed, and any exposed explanation for those choices. Execution tracing records the actions that occurred. Reasoning tracing records the inputs and stated intent so the team can check whether those actions fit the task.

The record needs the full context window passed to the agent, tool arguments before execution, and the stated plan or chain-of-thought where the framework exposes it. These provide the evidence needed to distinguish vague reports of unusual behavior from a diagnosis such as routing on stale account data fetched at step 2.

Pre-execution argument logging is a particularly useful capture point because it records what the agent intended to send before the tool fires. Post-execution logging alone does not provide that same view. Where a framework exposes a plan before action, comparing the two can reveal divergence between stated intent and actual behavior. That divergence can warn of context corruption before its damage is visible in the final response.

Defining "wrong" in a machine-checkable way before writing a single assertion

A team preparing to instrument semantic correctness should first define failure for the agent's specific task. Generic benchmarks cannot supply that definition wholesale. For support triage, failure could mean routing to the wrong queue or drafting a reply that violates the refund policy. For fraud detection, it could mean deciding on context that contradicts the account history provided.

Schema compliance is the first and narrowest criterion. It establishes whether the output has the expected structure, but a correctly shaped response can still encode a wrong decision. Policy adherence tests whether the action stayed within the constraints it had to follow. When those constraints are encoded, this level can detect refund-policy violations, permission boundary overruns, and routing errors.

Groundedness asks whether the agent's stated reasoning traces back to the documents and tool responses it actually received. This is the harder definition to make operational because the relationship between a claim and its supporting context must itself become checkable. Unsupported content must be distinguishable from content grounded in the supplied evidence. The minimum production scorecard should therefore include an eval score against the task-specific definition and eval drift over time. Uptime and latency remain useful, but neither substitutes for those measures.

Running online evals against live production traffic instead of a held-out test set

Offline evals test the situations a team anticipated. Production traffic brings context drift, schema changes, and new user inputs that a held-out test set cannot fully match. In the logistics case, an eval built before the API field rename would not have contained that change. Continuous evaluation of live tool responses was needed to detect the resulting failure at the point it entered production.

Online evals apply the task-specific definition to live outputs and alert on quality. The production signal is the decision's correctness. Other alerts can track score drops within a rolling window, tool-call sequences that are missing from the training distribution, and outputs that are much longer or shorter than usual. These anomalies flag behavior that may be wrong, while the eval checks it against the task.

Full evaluation of every trace is not required. Sampling routine traffic and running full evals on traces that trigger anomaly detectors provides a practical operating model when evaluation costs constrain coverage. Once a production failure is confirmed, its trace should automatically become a regression test. That preserves the actual failure case for later verification without requiring a hand-written assertion for every newly encountered pattern.

Instrumenting specific agent frameworks at the reasoning layer

OpenTelemetry GenAI semantic conventions provide a converging wire format for execution tracing across frameworks. The conventions remain in Development status, with no stable release as of late 2026. Even so, support in many frameworks means teams can get execution spans with little setup. Reasoning capture remains a separate engineering responsibility.

LangChain and LangGraph applications can receive execution tracing through the OpenTelemetry instrumentation package that explicitly supports both. Default spans leave out the reasoning steps in between actions, what is in the context window at each step, and how arguments are built before tool execution. The team must add instrumentation to capture those points beyond what execution tracing records.

OpenAI Agents SDK traces runs by default, collecting LLM generations, tool calls, handoffs, and guardrails for export to the Traces dashboard. For teams already on an OTEL stack, execution tracing requires no additional instrumentation code. Teams still have to do more work to capture what is in the context and log arguments before execution.

Vercel AI SDK 7 provides lifecycle events around model calls, tool executions, and agent runs. These events offer insertion points for context logging and pre-execution argument capture. The events cover steps in general but do not automatically show every reasoning sub-step.

Mastra reached v1.0 in January 2026 and introduced time-to-first-token and time-to-first-chunk latency metrics in November 2026. Its observability features trace agent calls and token usage and work with external observability platforms. As with the other frameworks, default execution instrumentation does not replace explicit logging of the context passed to each step. Framework choice determines which hooks need instrumentation.

Connecting detection to diagnosis to fix without reviewing traces one by one

Semantic detection becomes operationally useful when failures are grouped before engineers review them. A support-triage agent that repeatedly mis-routes billing requests after a prompt change presents one issue across hundreds of traces. Grouping by shared root cause exposes that pattern. Reviewing each trace separately instead obscures the common defect and delays correction.

The next step is an alert delivered where engineers already work, such as Slack or the coding agent. It should include the grouped issue, the drop in the eval score, and the trace context from the failure. Diagnosis then starts with the failure evidence available. Passing the trace, failure pattern, and failed eval to a coding agent over MCP lets it base a proposed fix on that evidence.

Verification must use the eval that detected the original failure. Running it against the patched agent tests the exact production case preserved as a regression. This connects the proposed change to a checkable result. For agents in finance, compliance, or customer-data workflows, the record also needs to be tamper-resistant. Once an agent mutates records or triggers payments, the evidence of what it saw, decided, called, and passed through policy checks serves as both an audit record and a debugging aid.

What a production-ready reasoning instrumentation stack looks like end to end

Diagram: From Silent Failure to Diagnosed Fix: Four Layers of Agent Observability. Visualizes: Show four sequential, stacked layers that together form a production-ready reasoning instrumentation stack.

A production-ready stack has four separate jobs, and each is needed. Execution tracing provides spans, latency, status codes, and tool-call success rates. Its role is to establish runtime health. Keeping that layer preserves the ability to distinguish infrastructure failures from decisions that were executed successfully but were wrong.

Reasoning capture supplies the decision evidence missing from execution traces. It records context windows at each step, arguments before execution, and exposed plans before action. Online evaluation then applies the task-specific correctness definition to live behavior. Rolling-window score alerts and automatic regression creation turn that evidence into a continuing quality signal.

Issue grouping connects those signals to engineering action. Shared failure patterns become contextual alerts, coding-agent MCP integration brings the evidence into the fix, and the original eval verifies the patch. Without this final layer, detection can leave the team with a growing review queue of unresolved defects. Without reasoning capture, the same workflow lacks the evidence needed to locate the cause.

For a team starting this work, the minimum viable addition is step-level tracing with context capture, one task-specific eval definition per agent, and an alert on eval score drift. These additions target the missing boundary directly. The practical test of the stack is whether a wrong decision can become a diagnosed and verified fix before a downstream business complaint becomes its first observable signal.

Filed underAgent Tracing

More in Agent Tracing