AI Agent Observability: What to Log in Production
Most agent logs store text, not decisions. Here is the trace schema, sampling policy and cost math that make AI agent observability work in production.
Your Agent Logs Are Useless. Here Is the Schema That Isn't.
A support triage agent we shipped for a logistics client ran clean for six weeks. Then on a Tuesday, 14 percent of refund tickets landed in the wrong queue. Nobody got paged. The dashboard was green. Latency was fine, error rate was zero, and the model had produced confident, well formatted, completely wrong routing decisions.
The cause took two days to find. A vendor had changed a lookup endpoint to return 200 with an empty array instead of 404 when a shipment ID was unknown. The tool call succeeded. The agent read "no results" as "no exceptions on this shipment" and routed to standard handling. Our logs had every prompt and every completion stored as pretty JSON blobs. They had no record of what the agent decided, why, or on what evidence.
That is the gap. Most teams instrument the text and skip the decision. Then they wonder why observability does not help during an incident.
Text logs are not traces
There is a reflex, inherited from web services, that says: log the request, log the response, you are covered. For a REST endpoint that is mostly true, because the function is one hop. An agent run is a tree. One user message becomes a planning step, four tool calls, two retrieval queries, a guardrail check, a retry, and a final answer. The interesting failure almost never lives in the first or last node.
When we audit agent systems before taking them over, the most common setup is a table with prompt, completion, latency_ms, tokens. You can answer "was it slow" and "was it expensive". You cannot answer "which step went sideways", which is the only question that matters at 2am.
The fix is not a vendor. It is a schema.
The span fields that actually answer questions
Every step in an agent run should emit a span with fields chosen because an on call engineer will query them, not because they were easy to capture.
| Field | Example | Question it answers |
|---|---|---|
trace_id / step_index | a91f... / 3 | Where in the run did this happen |
decision_type | tool_call, final, clarify | Did the agent act or answer |
tool_name | shipments.lookup | Which integration is implicated |
tool_args_hash | sha256:4c2e | Did two runs call the same thing the same way |
tool_result_shape | array[0], object{7}, null | Did the environment return something unexpected |
tool_latency_ms | 820 | Model problem or dependency problem |
retrieval_ids + scores | [d_441:0.72, d_12:0.31] | Was the evidence there at all |
model_id + prompt_version | claude-x / triage@v14 | Which change window does this belong to |
tokens_in / tokens_out / cost_usd | 9140 / 210 / 0.034 | What did this step cost |
guardrail_outcome | pass, blocked:pii | Did a policy fire silently |
terminal_status | success, max_steps, tool_error | How did the run end, not how it looked |
human_override | true | Did a person fix it after the fact |
Two of those are doing most of the work. tool_result_shape would have caught our logistics bug on day one, because an empty array where an object was expected is a one line alert. And human_override is the cheapest ground truth signal in the entire system, because it is a human telling you the agent was wrong, for free, in the normal flow of work.
Note what is not in the table: full prompt text on every span. Store it on a sample, store a hash always. More on that below.
Three questions your traces must answer in five minutes
We use these as the acceptance test for any agent observability setup. If a mid level engineer cannot answer all three without asking the person who built the agent, the instrumentation is not done.
- Which step diverged? Given a bad outcome, show the exact span where the trajectory stopped being recoverable. Not the final answer, the branch point.
- Was it the model or the environment? Separate "the model reasoned badly over good inputs" from "the model reasoned fine over garbage inputs". These have completely different fixes, and teams routinely patch prompts to work around broken integrations.
- How many other runs hit this? One click from a single trace to the population of runs sharing the same
tool_name,tool_result_shape, andprompt_version. Blast radius in under a minute.
That third one is what turns an anecdote into a decision. In the logistics case, once we could group by result shape, we found the bug had been present for nine days and touched 2,100 tickets, not the handful support had flagged.
Sampling: you cannot store everything, and you should not try
A chatty agent with 8 steps per run and 10k runs a day produces 80k spans a day. Store full payloads on all of them and your observability bill competes with your inference bill. We have seen a client paying more to watch the agent than to run it.
The policy we deploy by default:
- 100 percent of runs with
terminal_status != success, full payloads - 100 percent of runs with
human_override = true, full payloads - 100 percent of runs above the p99 cost or step threshold, full payloads
- 2 to 5 percent of the happy path, full payloads, random but stratified by prompt version
- 100 percent of all runs, skeleton spans only, no payload text
Full payloads live 14 to 30 days. Skeletons live 13 months, because that is what you need to answer "did this get worse after the model upgrade in March". Skeleton rows are small, a few hundred bytes, and they are the ones you aggregate over.
Cost per task is a reliability signal, not just a finance number
The metric most teams track is cost per million tokens, which is a vendor's unit, not yours. Track cost per completed task and steps per completed task.
On a document extraction pipeline we run, average steps per task drifted from 4.2 to 6.8 over three weeks. Spend went up 38 percent and nobody flinched, because the success rate on the dashboard still read 94 percent. What was actually happening: a PDF source had started emitting slightly different layouts, retrieval was missing on first attempt, and the agent was compensating with retries. Success held until it did not, and the step count had been screaming about it for 19 days.
Step count is a leading indicator. Success rate is a lagging one. Alert on the leading one.
Turning traces into evals instead of into screenshots
The point of all this is not a nicer dashboard. It is a feedback loop. The loop we run with clients:
- Failure or override gets tagged in the trace viewer, with a one word reason from a fixed vocabulary.
- Weekly, tagged traces get promoted into fixtures: inputs, tool responses recorded as they actually happened, expected outcome written by a human.
- Fixtures run in CI against every prompt, model, or tool change.
- Anything that appears three times and is not yet a fixture blocks the next release.
That last rule is the one with teeth. Without it the eval suite ossifies around the bugs you found in month one. Recorded tool responses matter too, because replaying against live integrations means your regression suite fails for reasons that have nothing to do with your change.
If your team is building this loop and wants a second set of eyes on the schema before it is wired into forty services, talk to us. It is cheaper to argue about field names now than to backfill a year of traces later.
Build or buy the viewer, but own the schema
| Option | Good when | Watch out for |
|---|---|---|
| OpenTelemetry plus your warehouse | You already have the pipeline, you want full control and long retention | You will build the trace UI and the diff view yourself |
| Open source LLM tracing tools | You want a trace viewer this week and self hosting matters | Schema drifts toward the tool's conventions, export path can be thin |
| Commercial eval and tracing platforms | You want traces, datasets and eval runs in one place | Per span pricing punishes chatty agents, and data residency needs a real answer |
Our bias: emit OpenTelemetry spans with your own semantic attributes, then point whatever viewer you like at the stream. The viewer is replaceable in a week. The schema and the eighteen months of history behind it are not.
One more thing, redact at the SDK boundary, not in the pipeline. Hash tool arguments, store retrieval document IDs instead of document text, and keep a separate consent gated store for raw payloads. Teams that defer redaction to "later in the pipeline" end up with customer data in three systems and a very awkward conversation with their DPO.
Monday morning
- Open your last five agent incidents and ask whether the trace alone explains each one. Count how many needed a conversation with the author.
- Add
tool_result_shape,terminal_statusandhuman_overrideto your spans. Those three are a day of work and cover a surprising share of production surprises. - Put steps per completed task on the same dashboard as success rate, and alert on a 25 percent week over week increase.
- Set the sampling policy, then check what your observability bill does over seven days.
- Promote the three most recent failures into CI fixtures, with recorded tool responses.
You do not need a new platform to do any of that. You need to decide that the unit of observation is the decision, not the string.
Weiterlesen

How to Test AI Agents: Evals That Catch Regressions
How to test AI agents when output is non-deterministic: the three layers worth testing, building a golden set from real traces, and where evals belong in CI.

Why AI Agents Fail in Production: 6 Failure Modes
Why AI agents fail in production is rarely a model problem. Here are the six failure modes we see in real deployments — and the controls that stop them.

Reviewing AI-Generated Code: A Process That Scales
Agents write most of the diff now. Here is a review process that scales: provenance tags, diff budgets, risk tiers, and the checks humans must still own.