
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
LLM tracing is the practice of recording every step an AI application takes to answer a request, from the user's input to the final output, as a structured timeline. Each model call, retrieval query, tool call and post-processing step becomes a span with its inputs, outputs, timing, token counts and errors, and all the spans for one request are grouped into a trace. When an agent gives a wrong answer, loops, or suddenly costs three times more, the trace is where an AI engineer looks first.
It matters because LLM apps fail in ways classic logs do not explain. A single user question can trigger a dozen model calls, a vector search and several API requests, and the bug is often in the middle: the wrong document was retrieved, a tool returned an error the model ignored, or a prompt template dropped a variable. Without tracing, you see only the bad final answer. With it, you can replay the exact path that produced it.
Traces, spans and attributes: the basic vocabulary
LLM tracing borrows its model from distributed tracing in backend systems. The OpenTelemetry documentation on traces defines a trace as the path of a request through an application, made of spans that represent units of work. Applied to an AI app, that looks like this:
Trace: one end-to-end request, such as "a user asked the support agent about a refund".
Span: one step inside that request, such as "retrieve top 5 chunks", "call the model", "run the lookup_order tool" or "validate JSON output".
Parent and child spans: spans nest. An agent step can contain a model call, which decides to call a tool, which itself makes an HTTP request.
Attributes: key-value details on each span: model name, temperature, prompt version, input and output tokens, latency, cost and status.
Events and errors: timestamped notes inside a span, such as a retry, a rate-limit response or a validation failure.
OpenTelemetry also publishes semantic conventions for generative AI, a shared naming scheme for attributes like the model requested, token usage and operation type. Using standard names means your traces can move between tools without rewriting your instrumentation.
Tracing vs logging vs monitoring
These three ideas overlap, but they answer different questions:
Logs tell you that something happened: "model call failed at 14:02". They are flat lines of text, hard to connect across steps.
Metrics and monitoring tell you how the system behaves in aggregate: average latency, error rate, daily token spend. Great for alerts, weak for explaining a single bad answer.
Traces tell you why one specific request behaved the way it did, step by step, with the data that flowed between steps.
In practice, teams use all three together. We cover the bigger picture in what AI observability is and why it differs from monitoring; tracing is the piece that makes observability actionable for an engineer debugging a real request.
What to capture in an LLM trace
A useful trace records enough to reproduce a decision without drowning you in noise. A good default for each request:
Request context: a trace ID, session or conversation ID, user or tenant ID (hashed if needed), app version and environment.
Prompts: the rendered system and user messages actually sent to the model, plus the template name and version that produced them.
Model calls: provider, model, parameters, input and output tokens, latency, cost and finish reason.
Retrieval: the query, the IDs and scores of the documents returned and which ones made it into the context window.
Tool calls: the tool name, arguments the model chose, the raw response and any error.
Outputs and checks: the final answer, schema validation results, guardrail decisions and, when available, user feedback such as a thumbs-down.
Be deliberate about sensitive data. Prompts and tool responses can contain personal or customer information, so production tracing usually needs redaction, sampling rules and retention limits agreed with whoever owns security and compliance.
How AI engineers debug with traces
Here is how tracing turns vague complaints into specific fixes:
"The agent gave a wrong answer." Open the trace and check the retrieval span. If the right document was never retrieved, the problem is chunking or search, not the prompt. If it was retrieved but ignored, look at prompt structure and context order.
"It got stuck in a loop." The span tree shows the agent calling the same tool with the same arguments again and again, often because a tool error was returned as plain text the model misread.
"It's slow." The timeline shows where the seconds go: a slow external API, sequential calls that could run in parallel, or a huge context. Our guide on why LLM apps feel slow covers the usual fixes.
"Costs jumped." Token counts per span reveal a prompt that grew, a retry storm, or an agent that now takes twice as many steps.
"It worked yesterday." Compare traces before and after a prompt, model or data change, filtered by version attribute.
From traces to evaluations
Tracing is also the raw material for quality work. Interesting production traces, especially failures and edge cases, can be saved into a test set and replayed whenever you change a prompt or model. Many teams attach automated scores to spans (did the answer cite a source, was the JSON valid, did a judge model rate it as correct) and track those scores over time. That loop, trace, label, evaluate, fix, is what separates a demo from an AI system a client can rely on.
Tools for LLM tracing
You do not have to build tracing from scratch. Common options include:
OpenTelemetry-based instrumentation, which sends traces to the observability stack a company already runs.
LLM-specific platforms such as LangSmith and Langfuse, which add prompt views, token and cost tracking, datasets and evaluation on top of traces.
Provider and framework features, since many agent frameworks emit spans automatically once you enable tracing.
The choice usually depends on where the client's data can live, which frameworks the app uses and whether the team already standardizes on OpenTelemetry. For a forward deployed engineer working inside a client's environment, that compatibility question often decides it.
Common mistakes
Tracing only the model call: most bugs live in retrieval, tools and glue code. Trace the whole request.
No version attributes: without prompt and app versions on spans, you cannot compare before and after a change.
Logging secrets and personal data: redact API keys, credentials and sensitive fields before they reach the tracing backend.
Collecting traces nobody reads: set up saved views for errors, slow requests and negative feedback, and review them regularly.
FAQ
What is the difference between a trace and a span?
A trace is the full journey of one request. A span is a single step inside it, such as one model call or one tool call. A trace is made of many nested spans.
Do I need tracing for a simple chatbot?
Even a single-call app benefits from recording prompts, outputs, tokens and latency. As soon as you add retrieval, tools or multiple steps, tracing becomes essential for debugging.
Is LLM tracing the same as AI observability?
Tracing is one part of observability. Observability also includes metrics, alerts, evaluations and dashboards built on top of the traced data.
Can tracing slow down my app?
Well-designed tracing sends data asynchronously and adds little overhead. High-traffic apps often sample a share of requests while always keeping errors.
Keep learning with Coderhouse
Instrumenting, debugging and evaluating LLM systems in production is core AI engineering work. Choose your next step:
Forward Deployed AI Engineering Course — for experienced developers and software engineers who want to build, evaluate and deploy RAG pipelines and agents that hold up in production.
Data Analytics Course — learn SQL, Python and statistics to analyze performance data like latency, cost and quality scores; no coding background needed.
GTM Engineer Course (waitlist) — join the waitlist to be the first to know when the program on automating go-to-market workflows with AI opens.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.