Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Explainer

Agent observability: what to log and why

What to record for AI agents in production: traces and spans, tool calls, cost per task and the signals that catch failures before users report them.

By 8 min readUpdated
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

Conventional monitoring tells you a service is up and how fast it responds. For an agent that is not enough. An agent can return HTTP 200 in two seconds with a confident, wrong answer, or finish a task correctly after forty model calls that cost a hundred times what they should. Observability for agents means recording enough about each run to answer three questions afterwards: what did it see, what did it do, and was it any good.

This explainer covers what to record, how to structure it, and which signals catch problems early.

The unit is the run, not the request

A web request has one input and one output. An agent run has a tree: the user’s request, several model calls, tool calls between them, maybe subagents with their own model calls. The natural record is a trace made of nested spans, one per step, each with a start time, duration and attributes.

run 7f3a (user: refund request)                       9.4 s   $0.031
├── model call 1        tokens in 2,140 / out 88     1.1 s
├── tool lookup_order   ok                            0.2 s
├── model call 2        tokens in 2,410 / out 64     0.9 s
├── tool issue_refund   error: amount over limit     0.1 s
├── model call 3        tokens in 2,590 / out 120    1.4 s
└── tool send_message   ok                            0.3 s

OpenTelemetry has semantic conventions for this shape (invoke_agent, chat, execute_tool spans with gen_ai.* attributes), still marked as in development. Using them means you can switch tracing backends without re-instrumenting. Trace an agent with OpenTelemetry builds one by hand.

What to record on every run

Always, cheaply:

  • A run ID and conversation ID, so you can find all runs for a user complaint.
  • The agent and prompt version, and the model name for every call. Without these you cannot tell whether a change made things better or worse.
  • Per model call: input tokens, output tokens, cache read and write tokens, latency, finish reason.
  • Per tool call: tool name, status (ok or error), error type, latency.
  • Per run: total cost, total duration, number of model calls and tool calls, how the run ended (completed, hit turn limit, error, cancelled).

When you can, with care:

  • Prompts, model outputs, tool arguments and tool results. These are what you need to debug, and they often contain personal or confidential data. OpenTelemetry’s GenAI conventions make capturing them opt-in for this reason. Capture fully in development, then decide per flow in production: sample, redact, or keep only for runs that fail.

From the outside world:

  • User feedback (thumbs, edits, “that’s wrong”), linked to the run ID.
  • Downstream outcomes when you can get them: was the refund reversed, was the pull request merged, did the user ask again.

Signals that catch failures

Some measures are noisy. These tend to point at real problems:

Signal Often means
Runs ending at the turn limit The agent is looping, or the task is underspecified
Model calls per run creeping up after a release A prompt or tool change made the agent less decisive
Same tool called repeatedly with the same arguments A loop, often after a tool error the agent does not understand
Tool error rate by tool A broken integration, or a tool description that leads the model to bad arguments
Cost per completed task (not per request) rising Context growing, cache misses, or retries
Cache read share falling Something dynamic crept into the start of the prompt
Very short runs with no tool calls on tasks that need them The agent is answering from memory instead of checking
Users rephrasing and retrying within a minute The answer was not useful, whatever the logs say

Alert on a few of these with thresholds based on your normal range, not on every metric you can compute.

Quality is the hard part

Latency and cost are easy to measure. Whether the agent did the right thing is not, and that is what users care about. Three layers help:

  1. Automatic checks on live traffic. Cheap code checks (valid JSON, required tool called, no forbidden tool) run on every trace. A sampled share of traces goes to an LLM judge for criteria like “answer consistent with tool results”. Langfuse, LangSmith and Phoenix can all run evaluators on stored traces.
  2. Human review. A weekly session reading twenty traces, chosen partly at random and partly from the alarms above, finds failure types no metric anticipated. Write them down.
  3. Offline evals. Turn the failures you find into test cases and run them before every release. Evaluate AI agents shows how.

Observability and evals feed each other: traces supply the cases, evals stop the same failures coming back.

Scheduled and background agents

Agents increasingly run with nobody watching: nightly dependency checks, issue triage on every new ticket, a weekly report. Claude Code’s cloud scheduled tasks run on a schedule, an API call or a GitHub event (Claude Code docs), and the Codex app and Cursor have their own scheduled runs and automations. Without a person reading the output as it appears, the record is all you have. Checked on 25 November 2026, three things make these runs different.

“Succeeded” does not mean the job was done. Claude Code’s run history marks a run as succeeded when “the session ended without Claude Code reporting a failure”, and says plainly that blocked network requests, missing connector tools and work Claude could not complete “appear in the transcript rather than on the row”. A green row can hide a run that did nothing useful. Record an outcome of your own: issues labelled, pull request opened, report delivered.

Runs can stop and wait. Cloud scheduled runs start in auto mode, and a run that hits auto mode’s repeated-block limit shows a permission prompt and waits until someone answers it. A run whose GitHub connection has lapsed is skipped, for up to 72 hours, until you reconnect. Neither looks like a failure unless you alert on runs that did not finish or did not start.

Refusals need their own signal. A tool call that a rule, a classifier or the sandbox stopped tells you either that the agent tried something it should not, or that the environment is missing something it legitimately needs. In Claude Code, query the claude_code.tool_decision OpenTelemetry event: it records each permission decision as accept or reject, with the auto mode classifier’s verdict when the classifier decided, though not always which rule refused the call. (A separate safety_event was added in v2.1.307 and dropped in v2.1.312, so ignore older guides that rely on it; see Claude Code monitoring.) Since v2.1.319 claude -p exits with status 1 instead of 0 when its actions were refused because no safety check was available (changelog). Count both.

For each scheduled or background run, record on top of the list above:

Field Why
Trigger (schedule, API call, event) and the schedule or event ID So you can find every run of one job, and spot one that stopped firing
Expected start time and actual start time Late or missing runs; Cursor’s docs, for example, say scheduled runs “may run with a delay but will not start before the indicated time” (Cursor docs)
The outcome you defined, as a field, not prose “Succeeded” from the platform is not enough
Refused or prompted tool calls, with the reason Missing access, or an agent trying something it should not
Whether the run waited for a person, and for how long A stalled run is a failure to the person expecting the result
What it changed outside itself (pull requests, comments, messages) The audit trail for work nobody saw happen

Alert on three things at least: a scheduled job with no run in its window, runs that end without your outcome field, and a rise in refusals after a change to rules or tools.

If you use Datadog, the directory lists skills that add LLM Observability instrumentation to an app and that trace failing spans to a root cause, and Datadog APM for the services around the agent. For a vendor-neutral start, trace an agent with OpenTelemetry builds the spans by hand.

Privacy and retention

Traces are among the most sensitive data an AI product stores, because they hold what users typed and what tools returned. Decide up front:

  • which flows may store content, and for how long;
  • who can read traces (support staff, engineers, vendors);
  • where the tracing backend stores data, and whether that matches your data-processing commitments;
  • how a user’s data is deleted from traces when they ask.

Self-hosting a tracing backend, or keeping content out of traces and storing only shape and metrics, are both legitimate answers.

A minimal starting setup

If you are starting from nothing this week:

  1. Emit one trace per run with spans for model and tool calls, with tokens, latency and status.
  2. Send it to one backend (a local Phoenix is enough to start; see LLM observability platforms compared).
  3. Build one dashboard: runs per day, cost per completed task, share of runs hitting the turn limit, tool error rate.
  4. Put thirty minutes a week in the calendar to read traces.
  5. Add evaluators once you know which failures matter.

Next steps

Covers

Back to top