AI

LLM Observability: What to Log and Trace in Production AI Features

4 min read by DebuggedIt

Quick answer

Quick answer: log every LLM call as a trace with the prompt version, model and parameters, redacted inputs and outputs, retrieved document IDs, tool calls,...

Quick answer: log every LLM call as a trace with the prompt version, model and parameters, redacted inputs and outputs, retrieved document IDs, tool calls, latency, token counts, cost, and errors. Track metrics for latency, cost, refusals, and retries, sample outputs for quality review, and redact sensitive data before it reaches your logs.

Why Is LLM Observability Different?

Traditional monitoring tells you whether a service is up and how fast it responds. An LLM feature can return a fast, successful response that is wrong, unhelpful, or unsafe, and nothing in your error rate will show it. Observability for AI must therefore capture content and context, not only status codes.

These systems are also non-deterministic and multi-step. A single user request might involve retrieval, several model calls, tool use, and post-processing. When an answer is bad, you need to see each step to find where it went wrong: the retrieved passages were irrelevant, the prompt was truncated, a tool returned an error, or the model ignored an instruction.

Cost is part of reliability as well. Token usage can spike because of a prompt change, a loop, or a verbose response, and the first sign may be the invoice. Per-request cost tracking turns this into an alert you can act on within hours.

What Should You Capture for Each Request?

Build a trace per user request, with a span for each step, and record enough to reproduce and debug it:

  • Identifiers: request ID, user or tenant ID, session ID, and timestamps.
  • Configuration: prompt name and version, model identifier, and generation parameters.
  • Inputs and outputs: the final prompt and response, with sensitive data redacted.
  • Retrieval: query, retrieved document IDs, and scores, so you can judge relevance.
  • Tools: each call with arguments, results, duration, and errors.
  • Performance: time to first token, total latency, input and output token counts, and estimated cost.
  • Outcome: finish reason, validation failures, retries, and any user feedback such as ratings or edits.

Prompt version and model identifier are the most valuable fields, because they let you correlate quality changes with deployments. Standard tracing formats and conventions exist for AI workloads, and using one makes it easier to integrate with the tools you already run.

Capturing full prompts and responses creates privacy risk. Redact personal data and secrets before storage, restrict who can read raw traces, set retention limits, and honor deletion requests. Consider storing full content only for sampled requests or for a short period.

Which Metrics and Alerts Matter?

Turn traces into a small set of metrics. Track latency percentiles, including time to first token, cost per request and per user, error and retry rates, schema validation failures, refusal rates, and token usage distributions. Watch the tail, because a few runaway requests can dominate cost.

Quality needs its own signals. Collect user feedback, track corrections and escalations to humans, and sample a fraction of production outputs for review by people or an automated grader calibrated against human judgment. Sudden changes in these metrics after a deployment point to a regression.

Alert on symptoms that matter: a jump in cost per request, a spike in validation failures, rising latency, or a drop in positive feedback. Keep dashboards segmented by prompt version and model, so a change in one path is not hidden by the average. Review failing traces regularly and turn them into regression tests.

Frequently Asked Questions

Should I log full prompts and responses?

Only with redaction, access controls, and retention limits. Many teams log full content for a sample and metadata for everything else.

How do I measure answer quality in production?

Combine user feedback, escalation rates, and sampled review by humans or a calibrated grader. No single metric is enough.

What is the most important field to log?

The prompt version and model identifier, because they connect quality and cost changes to specific deployments.

Do I need a specialized tool for LLM tracing?

Not necessarily. General tracing systems can carry the data. Specialized tools add conveniences, so evaluate them against your needs.

Summary

Trace every step of an LLM request with version, configuration, redacted content, latency, tokens, and cost. Monitor metrics and sampled quality, protect privacy, and turn failures into tests. Check your tooling documentation for supported conventions.