Skip to content
mentoor

Observability for an agent in production

For engineers

Trace a booking agent, read real traces, name its failure modes and decide what to detect, fix and keep out of the trace store.

An agent in production is observable when every run leaves a trace you can read, every failure is written down in plain words before it is named, and every failure mode you name has a detector that fires before a customer complains. Logs that say "request finished, 200 OK" tell you nothing about an agent that finished confidently and did the wrong thing.

The situation

Kestrel Travel runs a booking assistant. A customer writes "move my flight to next Friday". The agent calls search_bookings, then change_booking, then send_email, and answers in chat. It handles about 2,000 conversations a week. Two things have happened in one month. Support saw a cluster of thumbs-down ratings and a few double charges. Finance saw the model bill rise by a third with no new customers. Nobody can say why, because the only record is the chat transcript.

This case uses three skills: tracing, error analysis and agent failure modes.

Stage 1: make every run a trace

A trace is a tree of spans. The root span is the whole turn. Under it sit one span per model call, tool call and retrieval step. Each span records its start and end time, its inputs and outputs (see stage 4 on what to keep), token counts for model calls, and any error. Use the OpenTelemetry GenAI conventions for names such as gen_ai.request.model and gen_ai.usage.input_tokens, so you can change tracing backend later without re-instrumenting. Langfuse, Arize Phoenix and a general APM tool can all read them.

Stage 2: tag traces so you can find them

A trace you cannot find is useless. On the root span record a request id, a session id, an opaque customer id (never an email), the prompt version, the model name and the app release. Store each thumbs-down and each support ticket against the trace id. Now "ratings fell after Tuesday" becomes a filter on prompt version, not a hunch.

Stage 3: read traces and write notes

Pull 50 to 100 recent traces: all flagged ones plus a random sample. One person who knows travel reads each trace from the first span and writes one specific note, such as "searched with date 2026-14-03, tool returned empty, agent retried four times". Do not write "bad answer". Find the first step that went wrong; later errors usually follow from it. This is open coding. Only after the notes exist do you group them into a small set of failure modes and count them. Stop when a new batch of traces adds no new mode.

Stage 4: know which failure modes are agent failures

Grouped notes at Kestrel give four families. A loop: the agent searched six times with slightly different dates. A tool misuse: it called change_booking with an id it never found. A false success: it said "confirmation sent" and never called send_email. A hijack: a policy web page it fetched contained text telling it to email a passport scan elsewhere. Each family has a detector you can run on traces: a cap on consecutive empty calls, a check that ids came from a prior result, a comparison of the final claim with the tool log, and an allow-list on who the email tool may write to.

Stage 5: rank, fix, and keep the traces safe

Rank modes by frequency, severity and cost to fix. Two double charges a week outrank twenty slow answers. Prefer a code check (the same booking id changed twice in one turn) over an LLM judge when the trace makes the failure countable. Keep content capture on but redact secrets and personal data in the SDK before export, keep errors and flagged traces even when you sample the rest, and set a retention period.

Before and after

Before: "Users say it is flaky. Add more instructions to the prompt." After: "Of 60 reviewed traces, 9 show a retry storm after a rate-limit error, 6 show a double rebooking after a timeout. We added backoff and an idempotency key, and a nightly check counts both."

What goes wrong

  • Sampling 1 percent at random drops almost every failing trace.
  • Teams name failures from imagination, not from reading traces.
  • Traces copy passports and API keys into a vendor's database.
  • A fix is declared done because the agent says it is.

Steps

  1. Record each run as a tree of spans

    Skill: llmops-tracing

    Wrap the turn, each model call and each tool call in a span. Record time, token counts, the model name and any error. Use the OpenTelemetry GenAI attribute names so the backend can change later.

    Kestrel trace tr_8f21 (spans)
    agent.turn                      41.2s  customer=c_5521 prompt=v14  chat gpt_main #1              2.1s  in=2,340  out=96  tool search_bookings          0.3s  results=3 (6,100 chars)  chat gpt_main #2              1.9s  in=4,020  out=88  tool search_bookings          0.4s  results=3 (6,100 chars)  chat gpt_main #3              2.4s  in=7,950  out=91  tool change_booking           0.6s  status=confirmed  chat gpt_main #4             33.1s  in=118,420 out=140
  2. Tag traces with version and feedback

    Skill: llmops-tracing

    Put request id, session id, an opaque customer id, prompt version, model and release on the root span. Attach each thumbs-down and each support ticket to its trace id.

  3. Read a sample and write specific notes

    Skill: evals-error-analysis

    Read 50 to 100 traces, flagged ones first, from the first span onward. Write one observable note per failing trace. Group the notes into modes only afterwards, count them and stop when a batch adds no new mode.

    Open notes from the first review
    TraceNote
    tr_8f21Fourth model call carried 118k input tokens after three full search results were appended
    tr_9a07Searched with date 2026-14-03 four times, each returned empty
    tr_77c2Said confirmation email sent; no send_email call in the log
    tr_a310Called change_booking twice for BK-2210 after a timeout
  4. Name the agent failure families

    Skill: agent-failure-modes

    Match notes to loops, tool misuse, false success, hijack and drift. Each family gets a detector that runs on traces, such as a cap on consecutive empty calls or a check that every booking id came from a prior tool result.

  5. Rank failure modes and pick the fix type

    Skill: evals-error-analysis

    Weigh frequency, severity and fix cost. Use a code check when the trace makes the failure countable, an LLM judge only for judgment such as tone, and no permanent evaluator when a fix removes the cause.

  6. Keep traces safe and complete

    Skill: llmops-tracing

    Redact secrets and personal data before export, keep every error and flagged trace when sampling, restrict access and set a retention period.

Skills this scenario uses

Where to study