A single log line tells you a request happened and maybe how long it took. Distributed tracing instead builds a tree of nested spans—one per retrieval call, model call, or tool call—so when an AI answer is wrong, you can see exactly which step in the chain introduced the error, how many tokens it burned, and how long it took relative to its siblings.
Quick Answer: Instrument each retrieval, model, and tool call as a named span with a parent-child relationship to the request that triggered it, and attach token counts, latency, and a truncated input/output to every span. When something breaks, you read the trace tree top-down instead of guessing from one aggregate log line.
Why a Single Log Line Can't Explain a Multi-Hop Failure
A single log line answers "did the request succeed" but not "which of the five internal calls caused it to fail"—it collapses a chain of dependent decisions into one pass/fail bit with a total latency number. For any request touching more than one model or retrieval call, that's not enough information to debug.
Consider a realistic RAG-plus-agent flow: a user asks a question, the system retrieves documents, an agent decides whether to call a tool (say, a pricing API), the tool result gets summarized, and a final model call composes the answer. That's five hops minimum. A single log line might say request_id=8821, status=200, latency_ms=4200, tokens=3100—accurate, and almost useless.
What's missing is attribution: which of those five hops used 2,400 of the 3,100 tokens, which one added 3 of the 4.2 seconds, and—critically—which one handed the next step bad input. Google's original Dapper paper (the design most modern tracing systems, including OpenTelemetry, descend from) exists precisely because this problem predates LLMs: any request touching multiple services needs a shared trace ID and a causal tree, not an aggregate.
What a Trace Tree Looks Like for This Request
A trace tree turns the same request into five (or more) child spans, each independently timed and tagged, nested under one root span with a shared trace ID. Reading it top-down shows the causal order and lets you isolate which hop diverged from expected behavior.
For the RAG-plus-agent example, the tree might look like this:
root: answer_user_question(4.2s total)retrieve_documents(0.4s, 8 docs, top_k=8)vector_search(0.3s)rerank(0.1s)
agent_decide_tool_call(0.6s, 450 tokens)call_pricing_api(2.1s) — outlier, flaggedsummarize_tool_result(0.5s, 300 tokens)compose_final_answer(0.6s, 1,900 tokens)
Just from shape alone, call_pricing_api is the latency outlier—half the total request time—and worth investigating before touching any model prompt.
Spans, Parent-Child Relationships, and Trace Context in Plain PM Language
A span is a timed record of one unit of work—a retrieval call, a model call, a tool invocation—with a start time, end time, and whatever metadata you choose to attach. A trace is the full tree of spans for one request, connected by a shared trace ID and parent-child pointers.
Think of it like a project plan with sub-tasks. The root span is the epic ("answer this user question"); each child span is a task under it ("retrieve documents," "call pricing API"); and a task can have its own sub-tasks (the vector_search and rerank spans nested under retrieve_documents). The parent-child pointer is what lets tooling reconstruct the tree instead of showing you five unrelated log entries.
Three fields make a span useful for debugging, not just monitoring:
trace_id— shared across every span in the request, so you can pull the whole tree by one ID.parent_span_id— links each span to the step that triggered it, preserving causal order.span_nameplus attributes — what happened (call_pricing_api), and with what inputs, outputs, token counts, and status.
Without the parent-child link specifically, you get a flat list of timed events with no way to tell which retrieval fed which model call—exactly the ambiguity that makes multi-hop failures hard to root-cause. This is the core idea behind the llmops-observability-complete-guide, which frames tracing as one of three pillars alongside evals and cost monitoring.
Where This Differs From Traditional Microservice Tracing
LLM tracing borrows the span/trace model from traditional distributed systems but adds attribution dimensions those systems never needed: token counts, prompt/completion content, and model-specific cost per span. A traditional HTTP trace cares about latency and status codes; an LLM trace also needs to answer "was this a good generation," which latency alone can't tell you.
| Dimension | Traditional microservice trace | LLM application trace |
|---|---|---|
| Primary cost signal | CPU time, network latency | Tokens in/out, per-model $ rate |
| Failure mode | Exception, timeout, 5xx | Wrong retrieval, hallucinated fact, bad tool args |
| Span metadata | HTTP method, status code | Prompt, completion, retrieved chunks, tool arguments |
| "Correctness" check | Assertion / schema validation | Often needs an eval or human judgment |
| Standard | OpenTelemetry semantic conventions | OpenTelemetry + emerging GenAI semantic conventions |
The last row matters practically: the OpenTelemetry project has been extending its semantic conventions specifically to standardize how LLM spans capture model name, token usage, and prompt/completion attributes, so tooling built on top doesn't reinvent the schema per vendor.
Attributing Tokens and Latency Per Step, Not Just Per Request
Per-step attribution means tagging every span with its own token count and duration, then rolling those up to the request total—so instead of one number, you get a breakdown that shows exactly where cost and time actually went. This is the difference between "the request cost 3,100 tokens" and "the final compose step alone cost 1,900 of them."
Why this matters for a PM, not just an engineer: token and latency attribution turns a vague cost complaint ("our AI feature is expensive") into a specific, actionable target ("60% of cost is one summarization step that could use a cheaper model"). It's the same instinct behind building the three dashboards a product day one, applied at the level of a single request instead of an aggregate.
Attribution typically needs three things instrumented per span:
- Token counts — input tokens, output tokens, and (if applicable) cached tokens, since a cache hit costs differently than a fresh call.
- Latency — wall-clock duration of the span, plus time-to-first-token for streaming calls, since a slow start and a slow stream have different causes.
- Cost — token counts multiplied by the model's per-token rate at time of call, since model choice varies per step and rates change over time.
A Worked Example: Where the Budget Actually Goes
Below is a plausible per-step breakdown for the RAG-plus-agent request above, showing why aggregate numbers hide the real cost driver.
| Span | Tokens (in/out) | Latency | Model | Notes |
|---|---|---|---|---|
retrieve_documents | n/a | 0.4s | — | Vector search, no LLM call |
agent_decide_tool_call | 380 / 70 | 0.6s | small/fast model | Cheap decision step |
call_pricing_api | n/a | 2.1s | — | External API, not an LLM cost—but the biggest latency line |
summarize_tool_result | 220 / 80 | 0.5s | small/fast model | |
compose_final_answer | 1,600 / 300 | 0.6s | larger/flagship model | Most of the token cost, none of the latency problem |
Read this way, cost and latency have different culprits. The flagship model call is the token-cost driver; the pricing API call is the latency driver. An aggregate log line would have told you neither—only "4.2 seconds, 3,100 tokens, one request." That gap is exactly what turns quality drift into a debugging exercise with no stack trace when tracing isn't in place.
Reading a Trace Tree During an Actual Debugging Session
When an answer comes back wrong, the trace tree lets you walk the causal chain in order and check each span's input/output against what it should have produced—narrowing the search from "somewhere in five calls" to one specific span. This is the practical payoff of everything instrumented above.
A concrete debugging sequence, given the trace above and a user reporting the final answer quoted the wrong price:
- Open the trace by its ID and check
retrieve_documents—did it return the pricing-relevant document at all? If not, the failure is upstream of any model call, and no amount of prompt tweaking fixes it. - If retrieval looks right, check
agent_decide_tool_call—did the agent choose to call the pricing API, or did it try to answer from stale retrieved text instead? - If the tool was called, inspect
call_pricing_api's actual response payload—was the API itself wrong or stale? - Check
summarize_tool_result—did the summary preserve the exact price, or did it round, truncate, or paraphrase it into something wrong? - Only if all four upstream spans look correct do you inspect
compose_final_answerfor a hallucination introduced at the last step.
What a single log line would have given you here: nothing beyond "status 200, answer was wrong per user report"—forcing a from-scratch reproduction attempt with no visibility into which of five steps actually diverged. The trace tree turns a guessing exercise into a five-step elimination process, in the order the request actually executed.
Turning a Traced Failure Into a Reusable Signal
Finding the broken span is only half the value—the other half is making sure that specific failure mode doesn't require re-discovery next time. Closing the loop from failures to eval cases turns "we traced this once" into "we now have a regression test for it," so the same summarization-truncation bug doesn't silently reappear after the next prompt change.
That closing-the-loop step is also where the trace's span-level detail earns its keep: a good eval case needs the exact failing input and output, not a vague description—which is precisely what the summarize_tool_result span's captured attributes already contain.
Capturing the Fix Before the Trace Session Ends
The moment you find the broken span, you also lose momentum if the finding doesn't survive past the debugging session—by next sprint planning, "the summarizer truncates prices" is easy to half-remember and hard to prioritize. This is a workflow gap tracing tools don't solve on their own, since a trace UI is built for finding the bug, not for carrying it into planning.
Prodinja's Journals are built for exactly that handoff: while you're still looking at the broken summarize_tool_result span, you can capture a Friction or an Assumption on the spot, using real browser voice capture so the note is quick enough not to interrupt the debugging flow. It's a deliberately small, honest piece of the workflow—Prodinja doesn't trace your request or diagnose the span for you; it's the notebook that keeps the finding from evaporating between the trace tool and the next planning cycle.
Key Takeaways
- A single log line collapses a multi-hop request into one pass/fail bit—it can't tell you which of several model or retrieval calls actually broke.
- A span is a timed unit of work; a trace is the full tree of spans connected by a shared trace ID and parent-child pointers, borrowed from the Dapper-style tracing model used across distributed systems generally.
- Token, latency, and cost attribution belongs on each span, not just the request total—the flagship model call and the slowest call are often different steps entirely.
- OpenTelemetry's GenAI semantic conventions are emerging as the shared schema for LLM-specific span attributes (model, tokens, prompt/completion), so tooling doesn't reinvent this per vendor.
- Reading a trace during debugging means walking spans in causal order, checking each one's input/output against expectation until you find where it diverged.
- A traced failure should become a reusable eval case, not a one-off insight, so the same broken step doesn't silently regress later.
- Capturing the finding as a Friction or Assumption the moment you see it—in Prodinja's Journals or an equivalent tool—is what keeps a debugging insight from being lost before the next planning cycle.
Frequently Asked Questions
What is distributed tracing for LLM applications?
Distributed tracing for LLM applications is the practice of recording each retrieval, model, and tool call in a multi-step AI request as a nested span, connected by a shared trace ID, so you can see the full causal chain instead of one aggregate log line per request.
How do spans differ from regular application logs?
A log entry is typically a flat, timestamped message; a span is a structured, timed unit of work with explicit parent-child relationships to other spans in the same request. Spans let tooling reconstruct a tree—logs generally don't preserve that causal structure on their own.
What should I attach to each span for an LLM call?
At minimum, attach input and output token counts, latency (including time-to-first-token for streaming), the model name, and a truncated version of the prompt and completion. These four fields are usually enough to attribute both cost and quality issues to a specific step.
Do I need a dedicated observability tool, or can I build this myself?
You can instrument spans manually using OpenTelemetry's SDKs and its emerging GenAI semantic conventions, which several LLM-specific observability vendors also build on. Whether to build or buy usually comes down to how much trace-visualization and alerting tooling you want maintained for you versus in-house.
How does tracing relate to evals and cost dashboards?
Tracing tells you what happened in one specific request; evals tell you whether outputs are generally good across many requests; cost dashboards aggregate spend across all requests. They're complementary—closing the loop from failures to eval cases is what turns a single traced incident into an ongoing quality check, and the three dashboards a product needs on day one typically summarize what tracing surfaces per-request.