AI Agent Observability: Traces, Metrics and Cost Per Task
AI agent observability is the practice of recording what an AI agent did, step by step, so you can see why it reached a result: every model call, tool call, retry and handoff, with the tokens, latency, cost and errors of each. It turns an agent from a black box with a final answer into a trace you can replay, measure and fix.
The top guides on this query cover traces in depth, and a trace covers one run. Our team runs coding agents on real tickets every day, so we also get asked what a task cost, which model did it, whether it shipped and who checked it. This guide covers traces, metrics and that task-level record. Every attribute name and setting below was checked against the vendor's or the standard's own docs on November 13, 2026.
Key takeaways
- Agent observability has three layers: traces and spans (one run), metrics and evaluations (many runs), and the task record (one unit of work, from start to proof).
- The OpenTelemetry (OTel) GenAI conventions now name agent spans (
invoke_agent,execute_tool) and attributes such asgen_ai.agent.nameandgen_ai.usage.input_tokens. They are still marked Development, so pin a version. - Claude Code exports OpenTelemetry metrics and events, including
claude_code.token.usageandclaude_code.cost.usage, once you turn on telemetry and pick an OTLP exporter. Traces are in beta. - In our own agent clock data, 12 of 125 sessions had no model recorded and only 35 had token counts. Missing fields hurt more than missing tools.
- Pick tools by layer: a tracing tool for runs, your existing metrics stack for fleets, and a tracker that records the work for tasks.
What is AI agent observability?
In practice, agent observability means you can open any run and read it top to bottom: the prompt it got, the plan, each model and tool call, and where it stopped. Datadog's definition is short:
"AI agent observability is the process of tracing and analyzing an agentic system's decisions." (Datadog Knowledge Center)
IBM frames it with MELT data: metrics, events, logs and traces. Those signal types predate agents. A web service runs the same code path for the same request. An agent picks its next step at run time, so one request can take three tool calls on Monday and thirty on Tuesday.
Most teams already have some of this. LangChain's State of Agent Engineering report found 89% of teams have some agent observability and 62% have step-level tracing.
LangChain puts the cost of skipping it plainly:
"Without observability, you're left guessing why an agent failed based on its final output alone." (LangChain, Agent observability guide)
How is agent observability different from LLM observability?
LLM observability records single model calls with their prompt, completion, tokens and latency. Agent observability adds the loop around those calls, including the plan, the tools the agent picked, retries, handoffs to other agents or people, and whether the run met its goal.
| Question | LLM observability | Agent observability |
|---|---|---|
| Unit | One model call | One run (many calls and tools) |
| Typical failure | Bad or slow completion | Wrong tool, loop, stuck step, bad handoff |
| Key data | Prompt, output, tokens, latency | Trace tree, tool arguments and results, step count, spend per run |
| Evaluation | Output quality | Goal reached, steps taken, unsafe actions |
| Who reads it | ML engineer | Agent developer, on-call, team lead |
A third layer sits above both, and none of the top-ranking guides cover it: the unit of work. A coding agent's ticket may span four sessions, two models and a pull request. No single trace holds that.
What should you trace in an AI agent?
Trace every step that can change the outcome: the agent invocation, each model call, each tool call with its arguments and result, each retrieval, each handoff, and each human approval or rejection. Link them under one root span per run so the tree reads top to bottom.
A practical list, in order of value:
- Root run span. One per agent invocation, with the agent name, model, conversation or session id, and final status.
- Model calls. Model id as requested and as returned, input and output tokens, finish reason, latency.
- Tool calls. Tool name, call id, arguments, result or error, duration. Most agent bugs live here.
- Retrieval. Query, sources returned, and which ones the agent used.
- Handoffs and pauses. Calls to another agent, or waits on a person, with who and why.
- Outcome. Did the run do the job? This needs an evaluation or a human check, not just a 200 response.
LangChain's guide adds a useful threshold: once an agent chains two or more tools, or someone other than its author has to debug it, step-level tracing stops being optional.
Which OpenTelemetry attributes cover AI agents?
OpenTelemetry's GenAI semantic conventions define agent spans and a shared set of attributes, so traces from different frameworks look alike in any backend. The agent spans document is marked Status: Development, which means names can still change. The conventions moved out of the main spec into their own repository, semantic-conventions-genai.
The spans you will use most:
create_agentandinvoke_agentfor agent lifecycle and runs.execute_toolfor each tool call.- Model inference spans for the calls in between.
Here is a minimal attribute set we would copy into any agent today. Required ones are marked.
Agent run span (invoke_agent)
gen_ai.operation.name = "invoke_agent" (required)
gen_ai.provider.name = "anthropic" (required on the client invoke_agent span)
gen_ai.agent.name = "code-reviewer"
gen_ai.agent.id = "agent-7f2c"
gen_ai.request.model = "claude-opus-5-5"
gen_ai.conversation.id = "sess-2026-11-13-0412"
gen_ai.usage.input_tokens = 182400
gen_ai.usage.output_tokens = 9100
Tool span (execute_tool)
gen_ai.operation.name = "execute_tool"
gen_ai.tool.name = "run_tests"
gen_ai.tool.call.id = "toolu_01"
gen_ai.tool.type = "function"
Your own attributes (not in the spec, add them anyway)
work.ticket_ref = "TD-1234"
work.pr_url = "https://github.com/org/repo/pull/88"
The last two lines are ours. The spec has no field for the task a run belongs to, and that is the field you will search by most.
Why do threads and multi-agent runs need their own view?
A thread groups the turns of one conversation or task, and a multi-agent run groups the traces of several agents, so a failure that starts in turn two or in agent B shows up in the same place it began. Single-trace views hide both cases, because each trace looks fine on its own.
- Score at thread level. Judge whether the conversation or task reached its goal, not each turn alone.
- One trace per agent, one shared id. Give every agent its own trace and put the same
gen_ai.conversation.idon all of them so you can line them up. - Record every handoff. Log who handed off to whom, with what input, so you can tell a bad delegation from a bad worker.
What metrics matter for AI agents?
Track a small set per run and roll it up per agent, per model and per task. Datadog suggests treating success rate, unsafe-action rate, maximum steps and maximum spend as service level objectives with failure budgets, which is a good starting frame.
| Metric | Why it matters | Alert when |
|---|---|---|
| Task success rate | The only metric users feel | Drops week over week |
| Steps per run | Loops and wandering show up here first | Above your p95 |
| Tokens per run and per task | Cost driver, also a loop signal | A run uses several times its usual tokens |
| Cost per completed task | What finance and leads ask about | Rises without more output |
| Tool error rate | Broken integrations, bad arguments | Any spike |
| Latency per step | User wait, timeouts | p95 above budget |
| Human wait time | Where agents sit idle waiting on people | Grows faster than agent time |
| Unsafe or blocked actions | Guardrail health | Any rise |
Cost per completed task needs two sources: cost lives in traces, and "completed" lives in your tracker.
How do you get observability for coding agents like Claude Code?
Coding agents run on a developer's machine or in CI, not in your service, so your service's tracing never sees them. Claude Code solves part of this itself: it exports OpenTelemetry metrics and events once you enable telemetry and choose an exporter, sent over the OpenTelemetry Protocol (OTLP). From the Claude Code monitoring docs:
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
Langfuse accepts OTLP over HTTP only, not gRPC, so use OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf when pointing Claude Code at it.
The metrics include claude_code.session.count, claude_code.token.usage, claude_code.cost.usage, claude_code.commit.count, claude_code.pull_request.count, claude_code.lines_of_code.count and claude_code.active_time.total. Events include claude_code.tool_result and claude_code.api_request, and the docs describe the cost on that event as "Estimated cost in USD".
Traces are a separate beta signal. Set CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1 and OTEL_TRACES_EXPORTER=otlp and Claude Code emits one claude_code.interaction root span per prompt, with claude_code.llm_request and claude_code.tool children. Some attributes follow the GenAI conventions (gen_ai.request.model, gen_ai.tool.call.id), but it sends gen_ai.system rather than gen_ai.provider.name and sets no gen_ai.usage.* attributes, so expect a mapping step in your collector.
That gives you sessions, tokens and dollars per developer. It does not tell you which ticket the session served or whether the change was accepted. You add that link yourself, on the exporter or in the tracker where the work lives. To tag a session with its ticket, set this before launching the agent:
export OTEL_RESOURCE_ATTRIBUTES="work.ticket_ref=TD-1234"
It applies per session, not per prompt, and adds metric cardinality unless you set OTEL_METRICS_INCLUDE_RESOURCE_ATTRIBUTES=false. Our guide to running tasks in Claude Code covers how the agent picks up and reports on tickets.
Which AI agent observability tools should you consider?
Start with the layer you are missing. If you cannot debug a single run, get a tracing tool. If you cannot see trends, use your metrics platform. If nobody can say what a task cost, fix the task record. Every tracing tool below works with OpenTelemetry, so you can switch backends later without re-instrumenting.
| Tool | Layer | Source model | OpenTelemetry | Best for |
|---|---|---|---|---|
| LangSmith | Traces, evals | Commercial | Accepts OTel traces | LangChain and LangGraph teams |
| Langfuse | Traces, evals, prompts | MIT core, enterprise folder separate | Native OTLP ingest | Self-hosting with an open core |
| Arize Phoenix | Traces, evals | Elastic License 2.0 | Built on OTel | Local debugging and evals |
| OpenLLMetry | Instrumentation | Apache 2.0 | Emits OTel | Adding GenAI spans to any backend |
| Datadog LLM Observability | Traces, metrics, SLOs | Commercial | OTLP via Agent, Collector exporter or DDOT | Teams already on Datadog |
| Microsoft Foundry observability | Evals, tracing | Commercial | OTel based | Agents built on Azure |
| Work tracker with AI work records | Task record, cost per task, proof | Varies | Not a tracing tool | Coding agents doing ticketed work |
If you are asking "what's the best tool for AI observability", our pick per reader:
- You build agents on LangGraph: LangSmith, because the tracing is native.
- You want to self-host and keep data in house: Langfuse.
- You already pay for Datadog: its LLM Observability, so agent data sits next to the rest of your services.
- Your agents are Claude Code, Codex or Cursor working tickets: send their OTLP traces (a beta setting) to Langfuse, LangSmith or Phoenix and their metrics to your metrics platform, and keep the task record in a tracker that logs agent, model, tokens and cost per ticket. Our AI task manager guide compares the options.
Where does the task record fit in observability?
The task record is the top layer: one entry per unit of work that holds every session, model, token count, cost, file, commit and pull request behind it, plus the proof that it was done. You read a trace to debug a run and the task record to see what a piece of work cost and where it landed.
This is the gap we built Jenzo for. It is a ticket tracker where agents open, update and close tickets themselves over the Model Context Protocol (MCP) or the API. On each ticket, the agent runs its own work clock, separate from the person's timer, and reports input and output tokens. The work trail logs files touched, repo, branch, PR URL, commits, cost in USD, minutes and model. A ticket cannot close without proof: a link, or a closing report a quick judge model checks for substance.
Whatever tool holds it, a task record needs these fields:
Task record (one per ticket, many sessions)
ticket_ref, agent, model, minutes, input_tokens, output_tokens,
cost_usd, repo, branch, files[], commits[], pr_url, closing_proof
You still want a tracing tool next to it. The ticket is where you look up what a feature cost in agent time across four sessions. For the wider picture of running many agents, see our guide to an AI agent management platform.
What did our own agent data teach us about observability?
We pulled our team's agent clock records on November 13, 2026: 125 AI work sessions on 93 tickets, 3,139 active minutes in total. The median session ran 11 minutes. The longest hit the 4-hour cap.
Three lessons came straight out of the data:
- Missing fields beat missing tools. 12 of the 125 sessions had no model recorded, and one carried a nonstandard id. Only 35 sessions reported token counts. Any cost-per-model chart built on that data would be wrong, so every agent on our team now passes its model id when it starts its clock.
- Guards catch what nobody watches. 4 sessions were stopped by the idle rule (60 minutes with no ticket activity) and 4 by the 4-hour cap. Without those, an abandoned session inflates every average.
- Proof is an observability signal. Our tracker logged 272 close-with-proof events, and 26 thin closing notes were refused and rewritten. A refused note is a cheap, early sign that an agent did less than it claimed.
We now ask every agent to state its model id and ticket ref before the clock starts, because 12 of 125 sessions had no model.
What are the best practices for AI agent observability?
Instrument with open standards, trace every tool call, measure outcomes and not only latency, keep cost per task visible, and put humans where the risk is. Microsoft's five practices for Azure agents are a sound outline: pick models with benchmarks, evaluate continuously, put evaluations in CI/CD, red team before production, and monitor in production with tracing, evaluations and alerts.
Copy this checklist into your agent's README:
AI agent observability checklist
[ ] One root span per run, with agent name, model id and session id
[ ] execute_tool span for every tool call, arguments and result included
[ ] Input and output tokens on every model span
[ ] Ticket or task id attached to every run (custom attribute)
[ ] Telemetry exported over OTLP, not a vendor-only SDK
[ ] OTel GenAI semconv version pinned (spec is still Development)
[ ] Prompts and outputs redacted or sampled before export
[ ] Alerts on steps per run, token spikes and tool error rate
[ ] Eval set of 20+ real tasks, run in CI on every prompt or model change
[ ] Failed production traces added to the eval set each week
[ ] Human approval logged for risky actions, with who and when
[ ] Agent clocks stop on idle and cap, so stale sessions do not skew averages
[ ] Every closed task links its proof: PR, commit or report
The eval lines close the loop LangChain describes: every failed production trace becomes a test case, and the next prompt or model change has to pass it. Without that step, traces explain failures but never prevent the next one.
For the approval line, our guide to human in the loop AI shows which agent actions need a person and how to record the decision.
What are the challenges of observing AI agents?
The main challenges are volume, privacy, cost attribution and moving standards. Agents produce long traces with full prompts and tool outputs, which raises storage cost and the risk of logging secrets or customer data. Cost is spread across sessions and tools, so per-task numbers need a join you build yourself.
Practical answers:
- Volume: sample successful runs, keep all failed ones.
- Privacy: redact before export; most OTel collectors can drop or hash attributes.
- Attribution: attach a task id to every run, as in the attribute list above.
- Standards drift: pin the semantic conventions version and review it each quarter.
FAQ
What is observability in an AI agent?
Observability in an AI agent is the record of its steps, linked into a trace: inputs, plans, model calls, tool calls, results and handoffs, with tokens, latency, cost and errors on each. It lets you explain why the agent produced a result and find the exact step that failed, instead of guessing from the final answer.
What's the best tool for AI observability?
Pick by stack. LangGraph teams do well with LangSmith, teams that self-host pick Langfuse, and teams on Datadog use its LLM Observability. For coding agents working tickets, send their beta OTLP traces to one of these, their metrics to your metrics platform, and keep cost per task in your tracker.
What are the four pillars of observability?
The four pillars are metrics, events, logs and traces, often shortened to MELT. For agents, traces matter most, because they show the order of model and tool calls. Metrics cover tokens, cost and latency across runs. Events mark tool failures and handoffs, and logs hold prompts and decisions.
How can AI be used in observability?
AI helps observability in two ways. It can read traces and logs for you, for example by summarizing a failed run or answering questions in plain language about many traces. It can also act as a judge, scoring agent outputs in evaluations. Keep a human check on any judge that gates releases.
Is there open source AI agent observability?
Yes. Langfuse is MIT licensed outside its enterprise folders, OpenLLMetry and Opik are Apache 2.0, and Arize Phoenix is source available under the Elastic License 2.0. All of them work with OpenTelemetry, so you can start self-hosted and move to a managed backend later without rewriting instrumentation.
Why is observability called o11y?
O11y is a numeronym: the letter o, then 11 for the eleven letters between the first and last letters, then y. It follows the same pattern as k8s for Kubernetes and i18n for internationalization. Engineers use it as shorthand in tool names, channel names and conference talks.
Is Grafana an observability tool?
Yes. Grafana is an open source dashboarding and observability tool that visualizes metrics, logs and traces from many backends, including Prometheus, Loki and Tempo. For agents, you can send OpenTelemetry data from Claude Code or your framework to a collector and chart tokens, cost and errors in Grafana.
From our own experience
We assumed a tracing tool would answer our questions about agents. It answered how a run behaved, but not what a task cost or whether it shipped. What changed things was small: every agent states its model and ticket when it starts, stops on idle, and closes only with proof. The surprise was how much of our missing data traced back to agents skipping a single field.
Let your agents keep the board.
Claude Code, Codex and Cursor open their own tickets, log hours and tokens, and close them with the commit.
Connect your agent