How Do You Instrument AI Agents for Observability in Enterprise Production?
AI agent observability goes beyond APM. Instrument agents with OpenTelemetry, manage trace PII, and turn production failures into eval regression tests.
AI agent observability sits at the intersection of LLM engineering and distributed systems, and it is harder than monitoring either one in isolation. When an LLM processes a single prompt and returns a response, your APM can instrument the HTTP call, log the latency, and alert on errors. When an AI agent runs a multi-step task — calling tools, spawning sub-agents, reading from memory, retrying on failure, and aggregating results — a single request becomes a tree of spans, and the failure mode you care about is not whether the request timed out but whether the agent reached the correct conclusion through a valid reasoning path.
Most enterprise teams discover this gap the same way: they build a working agent, deploy it to production, and then realize they cannot answer basic operational questions. Why did this run cost three times more than average? Why did the agent loop four times on a task it normally completes in one pass? Which tool call is responsible for the 45-second tail latency spike? Which step in that workflow touched data the model should not have seen? Without purpose-built agent observability, these questions go unanswered until they become incidents.
This guide covers the complete observability stack for enterprise AI agent deployments in 2026: instrumentation with OpenTelemetry, trace pipeline design, PII handling, sampling strategies for high-volume agents, cost attribution, and closing the feedback loop from production failures to eval regression suites. If you are still designing the agent architecture itself, our overview of AI automation engineering practices covers the architectural decisions that make agents observable from the start.
What Is AI Agent Observability and Why Is It Different From APM?
Application Performance Monitoring was designed for systems where a request has a fixed structure: a process receives input, calls known dependencies, and returns output within a bounded latency. The spans in a traditional trace map cleanly to code paths your engineers wrote. AI agent observability must handle a fundamentally different structure: the agent decides at runtime which tools to call, in which order, how many times, and when to stop. The trace shape is non-deterministic, the latency distribution is fat-tailed, and the correctness signal is not a status code — it is whether the agent reasoned correctly and produced a useful, accurate output.
- →Multi-step, non-deterministic traces: a single agent run can produce hundreds of spans across tool calls, sub-agent invocations, retrieval steps, and model calls. The trace depth and width vary with the task, so static dashboards built for predictable call trees do not generalize.
- →Semantic correctness as a quality signal: HTTP 200 does not mean the agent answered correctly. Production agent observability requires online evaluators — lightweight LLM-as-judge or heuristic scorers — running against live traces to detect wrong answers, hallucinations, and missed tool calls before they accumulate into user-visible failures.
- →Cost as a first-class metric: each model call, retrieval query, and tool invocation has a measurable cost. Agents that loop, retry, or spawn sub-agents can run costs up by an order of magnitude without triggering any traditional alert. Cost per run, cost per sub-task, and cost anomaly detection must be built into the observability layer.
- →Identity and authorization in the trace: enterprise agents operate on behalf of users and access controlled resources. The trace must record which human principal triggered the run, what resources were accessed, and under what permissions — not just what the agent did, but on whose authority.
The Three Layers of an Enterprise AI Agent Observability Stack
A production-grade agent observability stack has three distinct layers. Conflating them is the most common architectural mistake, and it leads to teams either over-storing raw traces at unsustainable cost or missing the quality signals that make observability actionable.
- →Layer 1 — Instrumentation: the code-level work of emitting spans, logs, and metrics from the agent runtime. This layer is where you choose your instrumentation library (native framework adapters, OpenTelemetry SDK, or both) and define what data each span captures: model name, prompt tokens, completion tokens, tool call inputs and outputs, latency, and error codes.
- →Layer 2 — Trace pipeline: the infrastructure that receives raw spans, validates them, enriches them with metadata (user ID, session ID, environment, cost), applies PII redaction, samples based on volume and signal, and routes the result to a trace store and a real-time evaluation queue. This layer is the one most teams skip — routing raw spans directly to a backend and then discovering that the backend is expensive, the traces contain PII, and the noise-to-signal ratio is too high to debug with.
- →Layer 3 — Analysis and feedback: the backends, dashboards, and automated evaluators that consume processed traces. This includes the trace UI for debugging individual runs, the metrics system for aggregate quality and cost monitoring, the online evaluator for live quality scoring, and the export pipeline that turns failing production traces into regression test cases.
How to Instrument AI Agents with OpenTelemetry in 2026
OpenTelemetry is the correct foundation for enterprise agent instrumentation. It is vendor-neutral: the same spans can be routed to Datadog, Langfuse, Arize Phoenix, or your own trace store without re-instrumenting. The OpenTelemetry GenAI semantic conventions define a standard set of span attributes for model calls, covering model ID, input and output token counts, system prompt presence, and finish reason. Most major agent frameworks — LangChain, the OpenAI Agents SDK, Microsoft Agent Framework, and Google ADK — ship OpenTelemetry adapters that emit these conventions automatically.
- →Use framework adapters first: if your agent framework ships an OpenTelemetry adapter, enable it before writing custom instrumentation. Framework adapters capture the full call graph including sub-agents and tool calls with the correct parent-child span relationships. Custom instrumentation on top of an adapter is additive; custom instrumentation in place of an adapter typically misses sub-agent spans.
- →Instrument tool calls explicitly: tool call spans are the most diagnostically useful spans in an agent trace. Capture the tool name, the exact input arguments (redacting PII at the pipeline stage), the response, the latency, and any error. Teams that skip tool span detail consistently struggle to root-cause latency and correctness failures.
- →Add run-level root spans: each agent run should begin and end with a root span that carries the task description, the triggering user identity, the session ID, and the final outcome. This root span is what you query when you want to retrieve all traces for a user, a session, or a time window.
- →Propagate trace context across service boundaries: if your agent calls internal microservices — a retrieval API, a database proxy, a business logic layer — propagate the W3C trace context header so those calls appear as part of the same distributed trace. Without context propagation, tool call latency looks like a black box from the agent side.
Handling PII and Compliance in AI Agent Traces
Agent traces contain sensitive data by design. The prompt sent to the model may include user messages, retrieved documents, database query results, or email content — all of which can contain PII, PHI, or confidential business data. Storing raw agent traces in an observability backend almost always creates a compliance problem. The same governance principles that apply to agent sandboxing apply equally at the observability layer: you need a deliberate data handling policy before you go to production, not after.
- →Redact at the pipeline, not the source: apply PII detection and redaction in the trace pipeline layer, not in the instrumentation code. Redacting in instrumentation code means every developer who adds a span must also add redaction logic, which is error-prone. A centralized pipeline that scans all spans before storage is more reliable and easier to audit.
- →Tokenize rather than hash identifiers: for fields you need to correlate (user IDs, session IDs, document IDs) but cannot store in plaintext, use a consistent tokenization scheme rather than a one-way hash. Tokenization lets you retrieve all traces for a specific user during an investigation without storing the actual identifier.
- →Define retention tiers before scale: not all traces need to be stored at the same fidelity or for the same duration. Full-fidelity traces — including model inputs and outputs — should have a shorter retention period (days to weeks) in a restricted-access tier. Aggregate metrics and sampled traces can be retained longer for trend analysis. Define these tiers before your trace volume grows; retroactive deletion is painful.
- →Map traces to your compliance perimeter: for SOC 2, HIPAA, or GDPR compliance, agent traces must be subject to the same data classification and access controls as the production data your agents process. If your agents touch PHI, the trace store is in scope for HIPAA.
Sampling Strategies for High-Volume Enterprise Agents
A production enterprise agent handling thousands of runs per day generates trace volumes that make storing every trace impractical at any meaningful fidelity. Naive head-based sampling — keep a random 5 percent of traces — destroys the observability value: you lose the rare long-tail failures that are exactly the ones you need to debug. Enterprise agent observability requires a layered sampling strategy built around the signal value of each trace.
- →Always sample error traces: any run that terminates with an error, a timeout, or an explicit failure should be stored at full fidelity, unconditionally. These are the traces you will debug. Error sampling must happen before any other sampling decision.
- →Sample by cost anomaly: runs that cost significantly more than the rolling average for their task type are candidates for a bug, a prompt injection, or a runaway loop. A practical threshold is 3x the p95 cost for the task type. Sample these at high rate regardless of outcome.
- →Sample by quality signal: if you run an online evaluator on a sample of traces — which is recommended — store all traces the evaluator flags as low-quality or incorrect. Quality-based sampling ensures your trace store accumulates the failure cases most useful for improving eval coverage.
- →Use tail-based sampling for the remainder: make the keep-or-drop decision after the run completes, using the full trace as input. This is operationally more complex than head-based sampling but produces a much more representative sample of failures than random selection.
- →Store aggregates always: even when a trace is dropped from full-fidelity storage, increment the aggregate metrics — run count, cost, latency, outcome distribution. Aggregates are cheap and give you the trend signals that sampling otherwise loses.
Cost Attribution: Understanding What Each Agent Run Actually Costs
Cost attribution is the observability capability enterprise teams most consistently underinvest in until they receive an unexpected bill. An agent that spawns three sub-agents, each making four model calls and two retrieval queries, can run costs an order of magnitude higher than a single model call — and the cost may sit in a sub-agent invoked by another sub-agent, invisible in your LLM provider dashboard.
- →Track cost per span: each model call span should carry the input token count, output token count, and the model's current per-token pricing. Compute the cost for each span at instrumentation time and carry it forward in the trace. Do not rely on your LLM provider's billing dashboard for per-run cost attribution — it does not have the span-level context to allocate costs to specific tasks or users.
- →Aggregate cost per run, task type, and user: roll up span-level costs to the run level, then aggregate by task type and by triggering user or team. This lets you answer: which automation workflows are your most expensive? Which users or integrations are running unusually high-cost sessions?
- →Enforce per-run cost budgets: enterprise agent deployments should enforce a maximum cost per run at the orchestration layer. A run that exceeds its budget should surface an alert, pause for human review, or terminate with a specific error — not silently continue to accumulate cost. Budget enforcement is a risk control, not just a cost optimization.
- →Alert on cost anomalies before they accumulate: a cost anomaly detector that fires when a run's projected cost exceeds 3x the p95 for its task type catches runaway loops before they complete, not after they show up in the monthly invoice.
Connecting Production Traces to Your Eval Suite
The most important return on investment from agent observability is not debugging — it is the feedback loop from production failures to offline evaluations. Every production trace that reveals an agent failure is a free regression test case. Without a pipeline to capture and convert those cases, you are discarding the most valuable signal available for improving agent quality. Our guide to running LLM evals in the CI/CD pipeline covers the eval infrastructure in detail; this section covers the production-to-eval pipeline that feeds it.
- →Run online scorers against sampled production traces: an online scorer is a lightweight evaluator — an LLM-as-judge prompt, a regex, a heuristic, or a task-specific classifier — that runs automatically against a sample of production traces to flag low-quality outputs. The scorer does not need to be perfect; it needs to have high recall on the failure modes that matter to your business.
- →Export flagged traces as eval cases automatically: traces that fail an online scorer should be automatically exported to your eval dataset in a format your offline eval suite can consume. The input is the trace input; the reference is either a human correction or a model-generated reference; the label is the failure mode the scorer identified.
- →Run regression evals on every code or prompt change: every time you update the agent system prompt, change a tool implementation, or update the underlying model, run the accumulated production-derived eval set automatically. A failure on a known production case is a regression; treat it the same way you would treat a failing unit test.
- →Track eval coverage over time: the ratio of known production failure types that have at least one corresponding eval case is your eval coverage metric. Low coverage means production is discovering failure modes your eval suite has not captured yet. Track this metric and prioritize adding eval cases for the most frequent failure types.
Frequently Asked Questions
What is AI agent observability and how is it different from traditional application monitoring?
AI agent observability extends traditional APM to handle the non-deterministic, multi-step structure of agent runs. Where APM monitors latency, error rates, and throughput for known code paths, agent observability also tracks semantic correctness — did the agent reason correctly? — cost per run, and the full decision trace showing which tools were called, in which order, with what inputs. A production agent that returns HTTP 200 may have produced an incorrect or harmful output; traditional APM cannot detect this, but purpose-built agent observability can.
Do I need a dedicated AI observability tool or can I use my existing APM platform?
Your existing APM is necessary but not sufficient. Datadog, New Relic, and Dynatrace have added LLM monitoring modules that capture model call latency and token counts, and you should use them if you are already on those platforms — they integrate with your existing alert infrastructure. However, they do not provide online quality evaluation, production-to-eval export pipelines, or the semantic span structure that makes multi-step agent traces debuggable. The practical answer for most enterprises is APM for infrastructure and cost signals plus a purpose-built agent observability tool — Langfuse, Arize Phoenix, Braintrust, or LangSmith — for quality and debugging.
How do I handle PII in AI agent traces at enterprise scale?
Apply PII redaction in a centralized trace pipeline layer before traces reach any storage backend. Use a detection library such as Microsoft Presidio or AWS Comprehend to scan all span attributes that may contain user-supplied or retrieved content. Tokenize identifiers you need for correlation, apply shorter retention periods to full-fidelity traces, and ensure the trace store falls within the same compliance perimeter as the production data your agents process.
What sampling strategy should I use for high-volume production agents?
Use a tiered strategy: always store error traces unconditionally, apply quality-based sampling to keep traces flagged by online evaluators, apply cost-anomaly sampling for runs that exceeded their expected budget, and use tail-based sampling on the remainder. Store aggregate metrics for all runs regardless of whether the full trace is retained. Avoid head-based random sampling — it underrepresents the failure cases you need most for debugging and eval improvement.
How do I connect production traces to my offline evaluation suite?
Set up an online scorer that runs lightweight quality checks against a sample of production traces. Configure it to automatically export flagged traces — along with the input, the agent output, and the failure label — to your eval dataset. Run your eval suite against this dataset on every code or prompt change, and track eval coverage as a leading indicator of eval effectiveness.
How Belsoft Helps Teams Build Observable AI Agent Systems
At Belsoft, observability is designed into every agent deployment from the start, not retrofitted after the first production incident. When we partner with a company on AI transformation, we audit how the team plans to operate agents in production before the first line of agent code is written. That audit consistently surfaces the same gaps: no cost attribution, no PII strategy for traces, no eval feedback loop, and APM instrumentation that captures latency but misses correctness. We build the full observability stack as part of the deployment — instrumentation, trace pipeline, quality evaluators, and the export pipeline that turns production failures into regression tests. If you want to understand how this applies to your agents, schedule a conversation with our team.
The teams that treat observability as an afterthought are the ones who discover, six months after deployment, that their agents have been making systematic errors nobody caught — and that the data to debug those errors was never captured. Observable agents are not an engineering nicety; they are the foundation for a partnership that can improve over time.
“If you cannot observe it, you cannot improve it — and in production AI systems, what you cannot observe is already causing damage.”
Written by
Belal Hisham
Founder & Lead Engineer, Belsoft Solutions
More from the blog
Ready to partner?
Let's talk about your company.
30 minutes. No pitch. We talk through how you run today and where AI and automation would help.
Book a free audit