Volver a artículos

AI Agent Observability: What to Log in Production

8 min de lectura
AI
Agents
Observability
LLMOps
Reliability
Evals

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.

Compartir:LinkedInX

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.

FieldExampleQuestion it answers
trace_id / step_indexa91f... / 3Where in the run did this happen
decision_typetool_call, final, clarifyDid the agent act or answer
tool_nameshipments.lookupWhich integration is implicated
tool_args_hashsha256:4c2eDid two runs call the same thing the same way
tool_result_shapearray[0], object{7}, nullDid the environment return something unexpected
tool_latency_ms820Model problem or dependency problem
retrieval_ids + scores[d_441:0.72, d_12:0.31]Was the evidence there at all
model_id + prompt_versionclaude-x / triage@v14Which change window does this belong to
tokens_in / tokens_out / cost_usd9140 / 210 / 0.034What did this step cost
guardrail_outcomepass, blocked:piiDid a policy fire silently
terminal_statussuccess, max_steps, tool_errorHow did the run end, not how it looked
human_overridetrueDid 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.

  1. Which step diverged? Given a bad outcome, show the exact span where the trajectory stopped being recoverable. Not the final answer, the branch point.
  2. 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.
  3. 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, and prompt_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:

  1. Failure or override gets tagged in the trace viewer, with a one word reason from a fixed vocabulary.
  2. Weekly, tagged traces get promoted into fixtures: inputs, tool responses recorded as they actually happened, expected outcome written by a human.
  3. Fixtures run in CI against every prompt, model, or tool change.
  4. 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

OptionGood whenWatch out for
OpenTelemetry plus your warehouseYou already have the pipeline, you want full control and long retentionYou will build the trace UI and the diff view yourself
Open source LLM tracing toolsYou want a trace viewer this week and self hosting mattersSchema drifts toward the tool's conventions, export path can be thin
Commercial eval and tracing platformsYou want traces, datasets and eval runs in one placePer 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

  1. Open your last five agent incidents and ask whether the trace alone explains each one. Count how many needed a conversation with the author.
  2. Add tool_result_shape, terminal_status and human_override to your spans. Those three are a day of work and cover a surprising share of production surprises.
  3. Put steps per completed task on the same dashboard as success rate, and alert on a 25 percent week over week increase.
  4. Set the sampling policy, then check what your observability bill does over seven days.
  5. 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.

Compartir:LinkedInX