Quick answer

LLM failures often return a plausible wrong answer with a 200 status, so observability has to be designed in. Capture a trace ID, prompt version, retrieved document IDs, tokens, cost and latency on every call, trace chains as span trees, alert on time to first token, cost, cache hit rate and truncation, sample real outputs for review, and redact PII before storage.

When a normal application fails you get an exception, a stack trace and a line number. When an LLM feature fails you get a plausible paragraph that happens to be wrong, returned with a 200 status code. Nothing in your existing monitoring will notice, which is why LLM applications need observability designed in rather than added after the first incident.

What to capture on every call

{
  "trace_id": "...",              // ties every step of one user action together
  "span_id": "...",
  "parent_span_id": "...",
  "user_id": "...",               // hashed
  "feature": "support_reply_draft",
  "model": "...",
  "prompt_version": "v14",        // essential for attributing a regression
  "system_prompt_hash": "...",
  "messages": [ ... ],            // full input, subject to redaction
  "tools_offered": [ "search_kb", "create_ticket" ],
  "tool_calls": [ ... ],
  "output": "...",
  "finish_reason": "stop",
  "tokens": { "input": 3120, "output": 480, "cached_input": 2800 },
  "cost_usd": 0.0042,
  "latency_ms": 2310,
  "time_to_first_token_ms": 340,
  "retrieval": { "query": "...", "doc_ids": [...], "scores": [...] },
  "error": null
}

Three fields do disproportionate work. Prompt version lets you attribute a quality change to a specific edit instead of guessing. Retrieved document IDs distinguish a retrieval failure from a generation failure, which are entirely different bugs. And trace ID connects the six model calls behind one user action so you can read the whole story rather than six disconnected fragments.

Tracing chains and agents

Modern features are rarely one call. A support assistant might classify the ticket, retrieve policy documents, draft a reply, then check the draft against a rubric — four calls, any of which can be the problem.

Model this as a span tree, the same way you would trace a distributed request:

trace: draft_support_reply            4.8s   $0.011
├── span: classify_intent             0.4s   $0.0002
├── span: retrieve_policy             0.2s   —        (12 chunks, top score 0.81)
├── span: generate_draft              3.6s   $0.009
│   └── span: tool_call:search_kb     0.9s   —
└── span: self_check                  0.6s   $0.0018  (verdict: pass)

For agent loops, capture the iteration number and the stopping reason. "The agent looped nine times and hit the cap" is a completely different failure from "the agent answered in one step and was wrong", and without iteration data they look identical in the aggregate.

OpenTelemetry has emerging conventions for generative-AI spans, and most of the LLM observability platforms — Langfuse, Braintrust, Phoenix, LangSmith, Helicone — either build on it or export to it. Using a standard is worth it purely so the traces sit alongside your existing application traces rather than in a separate tool nobody opens.

Metrics worth alerting on

  • Time to first token, not just total latency. For a streamed interface, TTFT is what the user perceives as speed.
  • Cost per request and per user. A prompt change that adds 2,000 tokens of context is invisible in latency and obvious in the bill three weeks later.
  • Cache hit rate on prompt caching. A drop usually means someone made the cached prefix dynamic, and the cost doubles quietly.
  • Refusal and empty-output rate. A sudden spike almost always means a prompt or policy change.
  • Tool-call error rate and malformed-arguments rate — the most common cause of an agent that "just stops working".
  • Schema validation failure rate when you request structured output.
  • Truncation rate — outputs ending because they hit the token limit are silently incomplete.
  • Provider errors and rate limits broken out by type, with retry counts.

Alert on rate of change rather than absolute values. Quality drifts; it rarely falls off a cliff, and a threshold set once will either fire constantly or never.

Sampling for human review

Automated metrics tell you the system is behaving consistently, not that it is behaving correctly. Sample real interactions for a person to read:

  1. A small random sample — the baseline, and the only unbiased view.
  2. Everything a user rated negatively or edited heavily before sending.
  3. Outliers — unusually long, unusually short, unusually expensive, unusually slow.
  4. Anything that failed a guardrail or a self-check.
  5. Anything where retrieval scored poorly but an answer was produced anyway.

Half an hour a week reading real outputs catches things no metric will. Every problem found becomes a row in the eval set, which is how the review loop compounds instead of repeating.

Sensitive data

Prompts and completions contain whatever your users typed, which on many products means names, addresses, medical details and account numbers. Logging them wholesale creates a personal-data store with a long retention period and broad internal access.

  • Redact before storage, not on display. Run a PII detector over inputs and outputs and store the masked version.
  • Separate retention. Full payloads for days, redacted metadata and metrics for months.
  • Restrict access to the trace viewer and log who read what — it is production customer data.
  • Honour deletion requests, which means traces need to be findable by user ID.
  • Check your provider's retention settings. Zero-retention and no-training options exist on most enterprise tiers and are usually not the default.

The failure that observability exists to catch

Not the outage — you will hear about that. The quiet one: a model version updates, a prompt gets a well-meaning edit, a retrieval index drifts, and quality declines by a few percent a week. No errors, no alerts, no complaints for a month. Versioned prompts, per-case eval history and a weekly sample of real outputs are what turn that from a discovery into a notification.

Frequently Asked Questions

What should I log for every LLM call?

Log a trace ID and span IDs, the feature, model, prompt version, messages after redaction, tools offered and called, output, finish reason, token counts including cached input, cost, latency, time to first token and retrieval details. Prompt version, retrieved document IDs and trace ID do disproportionate work.

Which metrics are worth alerting on for an LLM application?

Time to first token, cost per request and per user, prompt cache hit rate, refusal and empty-output rate, tool-call error rate, schema validation failures, truncation rate, and provider errors with retry counts. Alert on rate of change rather than absolute values, since quality drifts instead of falling off a cliff.

How do I handle sensitive data in LLM logs?

Redact PII before storage rather than on display, keep full payloads for days and redacted metadata for months, restrict and audit access to the trace viewer, make traces findable by user ID so deletion requests can be honoured, and check the provider's retention settings, since zero-retention options are usually not the default.

Related Service

🤖 Business Process Automation

Business process automation with n8n, Zapier, Make, and AI — connect your tools, eliminate repetitive work, and let workflows run themselves around the clock.

Explore Business Process Automation →
Share this article
X Facebook LinkedIn