What happens to a user’s question after they hit send on a chat interface powered by a large language model? It rarely goes straight to the model. It passes through an API entry point, an authentication layer, a prompt builder, a retrieval step that queries a vector database, a tool-calling loop, and finally the model provider’s endpoint. If the answer arrives slow, wrong, or expensive, which of those hops is to blame?
That question is why LLM distributed tracing has become a core part of production AI engineering. It borrows the instrumentation model that microservice teams have used for years and adapts it to the strange, non-deterministic shape of model calls. This article explains how it works, what to instrument, where teams stumble, and how to keep trace data from becoming a privacy or cost problem.
What LLM distributed tracing actually means
Distributed tracing records the path of a single request as it moves through multiple services. Each unit of work becomes a span: a named, timed operation with a start, an end, and attributes. Spans nest into a tree, and the whole tree shares one trace ID. When a request crosses a service boundary, the trace ID travels with it, usually through HTTP headers.
LLM distributed tracing applies that model to model-powered applications. The twist is that a single user turn can spawn many model calls. An agent might plan, call a tool, read the result, call the model again, and repeat five times before answering. A retrieval-augmented pipeline might embed the query, search an index, rerank results, and then generate. Each of those steps deserves its own span, and they all need to hang off the same trace.
The payoff is diagnostic. A trace answers questions that logs and dashboards cannot: Was the latency in retrieval or generation? Did the agent loop three extra times? Which prompt version produced the bad answer? How many tokens did this one user request actually consume?
The standards holding it together

LLM tracing did not invent its own plumbing. It sits on top of mature, vendor-neutral standards, which is why traces from different frameworks can often land in the same backend. (Traces)
OpenTelemetry is the open standard for traces, metrics, and logs. It defines the span data model, the SDKs that produce spans, and the exporters that ship them to a backend. Most serious LLM observability tools emit or accept OpenTelemetry-compatible spans rather than a proprietary format.
W3C Trace Context is the recommendation that standardizes the `traceparent` and `tracestate` headers used to pass trace identifiers between services. It is the reason an LLM call made deep inside a backend can still be stitched into the trace that started at the browser-facing entry point.
On top of those, the LLM world added its own conventions. The OpenTelemetry GenAI semantic conventions define attribute names for model spans, covering things like model name, token counts, and request parameters. These conventions have been marked experimental, so attribute names can shift between releases. That instability matters in practice: a dashboard built on a draft attribute name may quietly break after an upgrade. Teams that pin their instrumentation versions and review the conventions before upgrading avoid most of that pain.
Separately, OpenInference defines span kinds tailored to AI workloads, such as LLM, CHAIN, RETRIEVER, TOOL, and AGENT, and maps them onto OpenTelemetry. And OpenLLMetry provides open-source instrumentations that wrap popular frameworks and SDKs so developers get spans without hand-writing them.
| Layer | What it standardizes | Why it matters for LLM apps |
|---|---|---|
| OpenTelemetry | Span model, SDKs, exporters | Vendor-neutral export to any backend |
| W3C Trace Context | Header format for trace propagation | Joins model calls to the wider request trace |
| GenAI semantic conventions | Attribute names for model spans | Consistent fields for tokens, model, parameters |
| OpenInference | AI-specific span kinds | Readable traces for agents, retrievers, tools |
| OpenLLMetry | Framework instrumentation | Auto-instrumentation instead of manual spans |
Anatomy of a well-instrumented LLM trace
A useful trace reads like a story. Here is the shape a healthy one usually takes for a retrieval-augmented chatbot.
- HTTP server span for the incoming request, carrying the user ID hash and session ID.
- Authentication and rate-limit spans, usually fast, useful for ruling out entry-point delays.
- Retrieval spans: the embedding call, the vector search, and the reranker, each timed separately.
- Prompt assembly span, recording the template version and the number of context chunks injected.
- LLM span with model name, input and output token counts, finish reason, and latency.
- Tool spans for any function calls the model requested, including success or failure.
- Post-processing span for guardrails, formatting, and streaming flush.
The most common mistake is instrumenting only the LLM call. That produces a trace that tells you the model took 2.4 seconds but not that retrieval took 6 seconds and the user waited 9. The second most common mistake is the opposite: capturing everything with no naming discipline, so spans appear as anonymous HTTP calls and the trace becomes unreadable.
A practical fix is a naming convention agreed on before launch. Something like `llm.generate`, `retriever.search`, and `tool.call` costs nothing to adopt and saves hours later.
Where teams get it wrong in practice
Several failure patterns show up again and again in real deployments.
Logging raw prompts by default. Prompts and completions frequently contain personal data, customer secrets, or regulated content. Sending them verbatim to a tracing backend turns an observability tool into a data store with its own compliance obligations. The common mitigation is to redact or hash sensitive fields at the instrumentation layer, before export, and to keep full content only in a tightly access-controlled store with short retention.
Treating token counts as native trace data. Token usage is not something tracing magically observes. It comes from the provider’s response metadata, and cost is derived from that plus a price table. When teams hardcode prices, cost dashboards drift after every model update. Pull pricing from configuration, and label the span with the model version so historical costs stay interpretable.
Sampling everything at full fidelity. LLM spans are large. A busy application can generate enormous trace volume, and storing every prompt is expensive. Head-based sampling decides at trace start and is cheap but can miss rare failures. Tail-based sampling decides after the trace completes, so it can keep all errors and slow requests while dropping routine successes. Most mature teams combine tail sampling for errors with content-free attributes on sampled-out spans.
Ignoring async and streaming paths. Streaming responses and background agent jobs break naive instrumentation. A span that ends when the HTTP connection closes may miss the final tokens and the true cost. Close the LLM span when the stream finishes, not when the handler returns.
No correlation with evaluation. A trace shows what happened; it does not say whether the answer was good. Teams that link trace IDs to evaluation scores and datasets can click from a bad score to the exact prompt, context, and model call that produced it. That link is where tracing starts paying for itself.
Choosing the right tooling without locking yourself in
The market splits into a few rough categories, and the choice matters less than the exit path.
| Approach | Strength | Watch out for |
|---|---|---|
| Open-source tracing platforms | Full data control, self-hosting | Operational overhead, upgrade work |
| Commercial LLM observability SaaS | Fast setup, built-in evals | Data residency, per-seat or per-span cost |
| General APM with LLM support | One place for all traces | Shallower LLM-specific views |
| Homegrown on OpenTelemetry | Total flexibility | You own the UI and maintenance |
The safest posture is to instrument against OpenTelemetry and treat the backend as replaceable. If your spans use standard attributes and standard context propagation, switching vendors is an exporter change rather than a rewrite. Teams that adopt a proprietary SDK with proprietary span formats often discover the migration cost only when pricing changes.
For teams still deciding how tracing fits alongside logging, metrics, and deployment practice, the broader write-ups in the blog section cover adjacent operational topics, and the cloud coverage looks at how hosted infrastructure choices affect observability costs.
Privacy, governance, and the data you should not keep
Tracing systems are seductive because they capture everything. That is also their risk. A few governance habits keep LLM traces defensible.
First, classify what a span may contain. Structural attributes such as model name, token counts, latency, and status are generally safe. Prompt text, retrieved documents, and model output are sensitive by default.
Second, apply redaction close to the source. A regex pass for emails, phone numbers, and account identifiers at the instrumentation layer is imperfect but catches the obvious cases before data leaves your network.
Third, set retention deliberately. Debugging needs days or weeks, not years. Short retention with sampled long-term aggregates gives you trend analysis without building a prompt archive.
Fourth, control access. Trace backends often have weaker access controls than production databases, which is backwards given what they can contain.
Finally, document the pipeline. Regulators and security reviewers increasingly ask where model inputs are stored and for how long. A one-page data-flow diagram of your tracing stack answers most of those questions.
Conclusion
LLM distributed tracing is not a luxury for large teams. The moment an application makes more than one model call per request, or adds retrieval, or runs an agent loop, the failure modes multiply faster than logs can explain them. Tracing turns those failures into a readable timeline.
The recipe that works is unglamorous: build on OpenTelemetry and W3C Trace Context, adopt the GenAI semantic conventions with a pinned version, name your spans consistently, redact sensitive content before export, sample with tail-based rules, and link traces to evaluation results. Do those things and the next slow answer or wrong answer becomes a five-minute investigation instead of a guess. For teams tracking how these practices evolve alongside the wider infrastructure landscape, the news section is worth following.
FAQ
What is the difference between LLM tracing and regular distributed tracing?
The mechanics are the same: spans, trace IDs, and context propagation. The difference is payload. LLM spans carry model-specific attributes such as token counts, model version, prompt templates, and finish reasons, and a single user request often fans out into many model calls through agent loops. That makes trace volume larger and content sensitivity higher than in typical microservice tracing. (W3C Trace Context specification)
Do I need OpenTelemetry to trace LLM applications?
No, but it is the safest default. OpenTelemetry gives you a vendor-neutral span format and a large ecosystem of exporters, so you can change backends without rewriting instrumentation. Proprietary SDKs can be faster to start with, but they raise migration costs later.
How do I stop prompts and personal data from leaking into traces?
Redact or hash sensitive fields at the instrumentation layer, before spans are exported. Keep full prompt content, if you must keep it at all, in a separate access-controlled store with short retention. Treat structural attributes like token counts and latency as safe, and treat prompt text, retrieved documents, and outputs as sensitive by default.
Why are my token and cost numbers wrong in dashboards?
Token counts usually come from the model provider’s response metadata, and cost is calculated from those counts plus a price table. If prices are hardcoded, dashboards drift whenever a provider updates pricing or you switch model versions. Store pricing in configuration and label spans with the exact model version used.
Should I sample LLM traces?
Usually yes, because full-fidelity LLM traces are large and costly. Tail-based sampling is often the better fit: it keeps every error and slow request while dropping routine successes. Pair it with content-free attributes so sampled-out spans still contribute useful latency and volume metrics.
How does tracing relate to LLM evaluation?
Tracing records what happened during a request; evaluation scores whether the output was good. Linking the two, by attaching eval scores to trace IDs, lets you jump from a failing score straight to the prompt, retrieved context, and model call behind it. That connection is where tracing delivers most of its debugging value.







