LLM observability: what to record on every request
LLM observability means you can explain any single response from recorded data. The fields to record, their OpenTelemetry names, and what not to store.
- Published
- Updated
- Reading time
- 10 min read
In short
- LLM observability is the ability to explain one specific response after the fact: which model answered, with what input, at what cost, and why it took that long.
- Record a trace per request, with a span for every model call, retrieval, and tool call. Instrument the application for context and capture at the gateway for coverage.
- Use the OpenTelemetry GenAI attribute names, such as gen_ai.request.model and gen_ai.usage.input_tokens, so any backend can read your data. They are still marked as in development, so pin a version.
- Do not record prompt and response text by default. Make it opt-in, redact it, keep it for a sampled slice of traffic, and give it a retention period measured in days.
LLM observability is the ability to explain one specific response after the fact. Given a request ID, you should be able to say which model answered, what it was sent, what it cost, how long each step took, and whether the answer was any good.
Standard application monitoring gets you part of the way. It breaks down on three points. The same input can produce different outputs. A request can return HTTP 200 and still be wrong. And the cost of two requests to the same endpoint can differ by orders of magnitude.
LLM observability vs LLM monitoring
LLM monitoring tells you that something is wrong. LLM observability lets you find out why. Monitoring watches known signals such as error rate, latency, and spend against thresholds. Observability records enough about each request to answer a question you did not plan for, such as which prompt version produced Tuesday's bad answers.
| Monitoring | Observability | |
|---|---|---|
| The question it answers | Is something wrong right now? | Why is this response wrong? |
| What it stores | Aggregated metrics | A trace per request, with attributes and sampled content |
| What you look at | A dashboard or an alert | One trace, opened from a request ID |
| Where it falls short | A wrong answer with a 200 status looks healthy | The request you need was not kept |
You need both. The alerts at the end of this article are monitoring, and they are useful because each one leads back to traces you can open.
What to record on every model call
Record nine fields on every model call. OpenTelemetry's GenAI semantic conventions give each a standard name, and using those names means any compatible backend can chart your data without custom mapping.
| What | Attribute | Why you need it |
|---|---|---|
| Operation | gen_ai.operation.name | Separates chat calls from embeddings and tool runs |
| Provider | gen_ai.provider.name | Compares providers and shows an outage at a glance |
| Model requested | gen_ai.request.model | What your code asked for |
| Model that answered | gen_ai.response.model | Gateways and aliases can change it |
| Input tokens | gen_ai.usage.input_tokens | Cost, and how fast context is growing |
| Output tokens | gen_ai.usage.output_tokens | Cost, and the main driver of total latency |
| Cached input tokens | gen_ai.usage.cache_read.input_tokens | Cache hit rate |
| Finish reason | gen_ai.response.finish_reasons | Truncated and refused answers look like successes without it |
| Time to first chunk | gen_ai.response.time_to_first_chunk | The wait a streaming user actually experiences |
The conventions stop there, and you should not. Add four attributes of your own: the version of the prompt template, the team or tenant that made the call, the number of retries, and the computed cost. Those are the dimensions you will group by during an incident.
Here is what an instrumented call produces. In practice an instrumentation library or your gateway emits this for you.
import { SpanStatusCode, trace } from "@opentelemetry/api";
const tracer = trace.getTracer("support-bot");
export async function tracedChat(request: ChatRequest) {
return tracer.startActiveSpan(`chat ${request.model}`, async (span) => {
span.setAttributes({
"gen_ai.operation.name": "chat",
"gen_ai.provider.name": "openai",
"gen_ai.request.model": request.model,
"app.prompt.version": request.promptVersion,
});
try {
const response = await client.chat.completions.create(request.body);
span.setAttributes({
"gen_ai.response.model": response.model,
"gen_ai.usage.input_tokens": response.usage?.prompt_tokens ?? 0,
"gen_ai.usage.output_tokens": response.usage?.completion_tokens ?? 0,
"gen_ai.response.finish_reasons": response.choices.map((c) => c.finish_reason),
});
return response;
} catch (error) {
span.recordException(error as Error);
span.setStatus({ code: SpanStatusCode.ERROR });
throw error;
} finally {
span.end();
}
});
}Why a trace and not a log line
Use a trace because one user request is a tree of work, and a log line flattens it.
A typical request runs a retrieval query, one or more model calls, perhaps several tool calls, and a guardrail check. A trace keeps each as a span with its own timing and its parent. When a response is slow you can see which step was slow. When it is wrong you can see what the model was given at the moment it answered.
Agents make this matter more. A single task can run dozens of model and tool calls, and the bad decision is often ten steps before the visible failure. The conventions define span types for tool execution and agent invocation so that tree stays readable. AI agent observability covers how to record a whole run and the failures that only show up at that level.
Where to capture the data
Capture LLM telemetry in two places: inside the application, where you know which user, feature, and retrieval step a call belongs to, and at the gateway, which sees every model call from every service without code changes. Provider dashboards are a billing cross-check, not an observability source.
| Capture point | What it sees | What it misses | Cost to adopt |
|---|---|---|---|
| Instrumentation in the application | Retrieval, tool calls, prompt version, user, feature | Services nobody instrumented | A library per service and language |
| An LLM gateway | Every model call, with consistent token, cost, and latency fields | Retrieval, local tools, and context the application did not send | One deployment and a base URL change |
| The provider's dashboard | Billed usage per key or project | Anything per request, and other providers | None |
The two views join through trace context. If the application forwards the W3C traceparent header, the gateway's spans land inside the application's trace, so coverage and business context end up in one tree.
Gateway capture is the fastest way to cover a fleet of services. Bifrost, an open-source AI gateway by Maxim AI, records each request it routes and can export OpenTelemetry traces that follow the GenAI semantic conventions, so the attribute names in the table above arrive with no code in your services. It also exposes Prometheus metrics for tokens, cost, and latency, labeled by provider, model, virtual key, team, and customer, and it has connectors for Datadog, Kafka, BigQuery, Pub/Sub, and Splunk.
Content is a separate switch, which is the right design: disable_content_logging keeps model, token, cost, and latency metadata while dropping prompts and responses, and each connector has its own setting.
Tracking cost by team, key, and model
Compute the cost of each request from its token counts when you record the span, and attach the dimensions finance will ask about: team, key, feature, and model. A provider invoice gives totals per account. It cannot tell you which feature or customer spent the money.
Four details decide whether the number is right:
- Price input, cached input, and output tokens separately. Cache reads and writes are billed differently from ordinary input, as the prompt caching article explains.
- Count reasoning tokens. OpenAI's reasoning models bill them as output tokens even though they are not visible in the response. The count is under
output_tokens_detailsin the usage object. - Count retries. A request that retried twice made three billed calls.
- Keep the token counts next to the computed cost, so you can recompute history when prices change.
Group spend by the same keys you use to enforce limits. If budgets are set per virtual key, report per virtual key, so the number on the dashboard is the number that blocks requests.
What not to record
Do not record prompt and response text by default. The conventions say instrumentations should leave content out unless the user opts in, and they are right.
Content is where the risk sits. Prompts contain whatever your users typed: names, account numbers, medical details, pasted credentials. A trace store holding all of it becomes one of the most sensitive databases you run.
Content is also the most useful thing to have when you debug a wrong answer. Resolve the tension with a policy:
- Capture content for a sample of ordinary traffic and for every request that errored or was flagged.
- Redact personal data before the span leaves your process.
- Store large payloads by reference and keep the span small.
- Set a retention period measured in days, not years.
The OpenTelemetry Python instrumentations expose the opt-in through the OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable. It is off unless you turn it on. Community libraries use switches of their own, so check each one you install.
Sampling and retention
Keep metrics for all traffic, traces for most of it, and content for a small, deliberate slice. Decide after a request finishes, so errors, slow requests, and flagged answers are always kept even when ordinary traffic is sampled down.
Deciding up front is head sampling: a coin flip at the start of the trace, which throws away the one failed request in a thousand that you needed. Tail sampling waits for the trace to complete and then applies rules. The OpenTelemetry Collector's tail sampling processor does this with policies such as status_code, latency, and probabilistic, holding spans in memory while it decides.
| Data | Keep it for | What to sample |
|---|---|---|
| Metrics: counts, tokens, cost, latency histograms | Months | Nothing. Record all traffic |
| Traces without content | Weeks | All traffic, or tail-sampled at high volume |
| Prompt and response content | Days | Errors, flagged answers, and a small random share |
| Evaluation scores | As long as the trace | Every request that was graded |
You can only grade an answer you kept, so the content sample is also the pool your online evaluations draw from. LLM evaluation covers how large it needs to be.
LLM observability tools
LLM observability tools fall into three groups: instrumentation libraries that emit OpenTelemetry data, LLM-specific backends that store traces and run evaluations, and general observability platforms that added LLM views. Choose the instrumentation first, on open conventions, so changing the backend later is a configuration change.
| Tool | Group | What it is |
|---|---|---|
| OpenTelemetry GenAI instrumentations | Instrumentation | The official libraries for the conventions in this article |
| OpenLLMetry | Instrumentation | Apache 2.0 extensions on OpenTelemetry for model APIs, vector databases, and frameworks |
| OpenInference | Instrumentation | Apache 2.0 conventions and plugins that complement OpenTelemetry |
| Langfuse | LLM backend | Open source and self-hostable: tracing, evaluation, and prompt management |
| Arize Phoenix | LLM backend | Self-hostable under the Elastic License 2.0, with tracing on OpenInference |
| Datadog LLM Observability | General platform | Traces, tokens, errors, cost, and evaluations next to your other Datadog data (our breakdown) |
The table is a map, not a ranking. The choice that is hard to reverse is the instrumentation. If your spans use the GenAI conventions, moving to another backend means pointing the collector somewhere else.
What to alert on
Alert on a handful of signals that map to user-visible or budget-visible problems:
- Error rate split by class. A rise in rate-limit errors and a rise in overload errors need different responses, as the gateway article explains.
- The 95th percentile of time to first token, per model.
- The share of responses that finish with
length. That is truncation, and users see half an answer. - Cost per request and per tenant against a budget.
- Cache hit rate. A sudden drop means someone changed a prompt prefix, covered in the prompt caching article.
- A quality score from automated evaluation on sampled traffic.
Do not alert on average latency. Total latency scales with output length, so the average moves whenever users ask longer questions. Time to first token is the stable signal.
The last item on the list is what turns monitoring into observability. Attach each evaluation score to the trace it grades, and you can ask which prompt version, model, or input size the bad answers have in common. The hallucination detection article covers how to produce that score.
The conventions are still moving
Every GenAI convention in OpenTelemetry is marked as in development, and names have changed more than once. The provider attribute used to be gen_ai.system. It is now gen_ai.provider.name. The conventions have also moved out of the main semantic conventions repository into one of their own.
Two habits keep that from hurting. Pin the version of your instrumentation library and upgrade it on purpose. Keep attribute names in one module in your code, so a rename is a one-line change and not a search across services.
Frequently asked questions
What is LLM observability?
LLM observability is recording enough about each model request to explain any single response later: the model that answered, its input, the tokens and cost, the time each step took, and a quality score where you have one. It is built on traces, with one span per model call, retrieval, and tool call.
What is the difference between LLM monitoring and LLM observability?
Monitoring checks known signals such as error rate, latency, and spend against thresholds, and alerts when one crosses. Observability keeps per-request detail so you can investigate questions you did not plan for, such as why answers got worse after a prompt change. Monitoring says something is wrong. Observability says why.
What should you log for an LLM request?
Log the operation, provider, requested and responding model, input, output, and cached tokens, finish reason, and time to first chunk, using the OpenTelemetry GenAI attribute names. Add your own prompt version, team, retry count, and computed cost. Leave prompt and response text out by default.
Should you store prompts and responses in your traces?
Store them for a deliberate slice, not for everything. Content is what you need to debug a wrong answer and the most sensitive data you hold. Keep it for errors, flagged answers, and a small random sample, redact personal data before export, and delete it after days.
Is OpenTelemetry ready for LLM tracing?
It is usable today, and most LLM observability tools accept its data. The GenAI conventions are still marked as in development, and names have changed: gen_ai.system became gen_ai.provider.name. Pin your instrumentation version, keep attribute names in one module, and upgrade on purpose.
Do you need a separate LLM observability tool if you already use Datadog or Grafana?
Not always. If your main problems are latency, errors, and cost, adding GenAI spans to the platform you run keeps model calls next to the database and service calls around them. A dedicated LLM backend earns its place when answer quality is the main question, because it is built around evaluations and prompt versions.
Sources
- 01Semantic conventions for generative AI systemsOpenTelemetry
- 02semantic-conventions-genaiGitHub, OpenTelemetry
- 03Generative AI spansGitHub, OpenTelemetry
- 04GenAI attribute registryGitHub, OpenTelemetry
- 05OpenTelemetry OpenAI instrumentationOpenTelemetry docs
- 06Tail sampling processorOpenTelemetry Collector
- 07Reasoning modelsOpenAI API docs
- 08OpenLLMetryGitHub, Traceloop
- 09OpenInferenceGitHub, Arize AI
- 10Langfuse documentationLangfuse
- 11PhoenixGitHub, Arize AI
- 12LLM ObservabilityDatadog docs
- 13OpenTelemetry tracingBifrost docs
- 14Prometheus metricsBifrost docs