You’re an engineer responsible for helping to manage your company’s AI assets. Part of your job is preventing wasteful spending due to unnecessary token consumption.
In tracking token usage, you notice that it’s high whenever an employee prompts your primary large language model (LLM) with questions related to sales. But based on this observation alone, you have no way of knowing exactly what’s causing the wasteful token consumption. Maybe the prompts are poorly structured. Maybe they cause the LLM to make API calls that use tokens inefficiently. Maybe the LLM is retrieving information from a local database that is poorly structured, leading to repeated queries and wasted tokens.
The only way to tell the difference is through LLM tracing. By generating an LLM trace that records every action that takes place between the initial prompt and the final response, you can gain granular insight into LLM behavior and trace the problem to its root cause.
Read on for details as we explain what LLM tracing means, how it works, what to include in traces, and tips on tracing LLMs as effectively as possible.

What is LLM tracing?
LLM tracing is the practice of creating records of every action within an LLM-based workflow – from a user’s prompt, to tool calls or data retrieval, to formulation and delivery of the final response.
The purpose of LLM traces is to provide step-by-step visibility into what happens when an LLM processes a request. This insight helps engineers troubleshoot problems like inaccurate, poorly structured, or incomplete responses. It can also help them optimize the speed at which LLMs generate responses.
LLM tracing vs. traditional application tracing
The concept of tracing isn't unique to LLMs. You can also generate traces for traditional applications by recording every action they perform when responding to a request. Tracing is especially valuable for gaining insight into microservices-based applications, since it makes it possible to understand how data flows between microservices and trace problems to the specific microservice that causes them.
That said, while the core concepts behind LLM tracing and traditional application tracing are the same, the difference lies in the types of events that are actually recorded to generate a trace. With LLM tracing, track prompts, data retrievals and tool or API calls. With application tracing, they look at an application’s internal functionality.
Sometimes, LLM tracing and traditional tracing can be used together. If an LLM trace reveals that a tool or API called by an LLM introduces an issue into the LLM’s workflow, an application trace might help pinpoint what the tool or API is doing wrong. But this would involve creating two distinct traces (one for the LLM and one for the tool or application) using different tools.
LLM tracing vs. LLM observability
LLM tracing is one component of LLM observability, meaning the practice of understanding LLM performance and behavior. But LLM observability is a broader concept that also includes practices like performance metric assessment and model accuracy evaluation.
The relationship here is very similar to the one between traditional application tracing and application observability. It’s often said that there are three “pillars” of observability – logs, metrics, and traces. By the same token, there are three pillars of LLM observability: Log analysis, metrics assessment, and tracing.
The anatomy of an LLM trace
Every LLM trace includes three discrete types of information: The trace itself, the spans within the trace, and metadata and telemetry associated with the trace. Here’s a closer look at what each entails.
Traces: The top-level record of a full request lifecycle
A trace is the complete, top-level record of an LLM’s request-response cycle. The amount of information within a trace can vary depending on how complex the cycle is; for example, if the LLM doesn’t perform any tool calls or retrieve external data, the trace would be relatively short.
Spans: Discrete sub-operations within a trace
Spans are individual actions within an LLM request-response lifecycle. The main examples of spans include:
- Prompts.
- Tool or API calls.
- Data retrieval.
- The final response that the LLM displays to the user.
Again, not every trace includes each of these types of spans. Simple traces may include just a prompt and a response.
Metadata and telemetry: Token usage, cost, latency, and model weights
Metadata and telemetry represent data that the LLM doesn’t process itself, but that provide critical context about each span. Examples of this type of data include:
- The total tokens consumed during the request-response lifecycle.
- The latency of the response (meaning how long it took the LLM to respond to the request).
- Model weights, which engineers can configure at runtime to influence model behavior.
How LLM tracing works in practice
To make an LLM traceable and generate traces, engineers first need to instrument the LLM for tracing. Instrumentation is the process of exposing spans and metadata so that they can be collected. It’s critical because LLMs don’t generate traces on their own.
There are multiple approaches to implementing instrumentation:
- Using instrumentation libraries: Libraries like LangChain and LangGraph can automatically instrument an LLM for tracing. However, this approach isn’t always possible when using third-party LLMs.
- OpenTelemetry/OTel GenAI Semantic Conventions: Although the OpenTelemetry standard was created for traditional applications, it can be extended through GenAI Semantic Conventions to enable LLM tracing. Once instrumented this way, LLMs can generate traces that engineers can collect and analyze using any OpenTelemetry-compatible tool.
- eBPF: The extended Berkeley Packet Filter (eBPF) can collect tracing data by monitoring LLM activity via the Linux kernel. This approach offers a highly efficient means of getting granular insight into LLM spans. A limitation is that eBPF is currently only fully supported on Linux, so it can only support LLM tracing in environments where LLMs run on Linux servers.
Sampling decisions and what you risk losing
A challenge that can arise when performing LLM tracing is the high resource consumption associated with collecting and analyzing every trace. If you perform frequent traces, the CPU and memory required to generate each one can become significant. Large volumes of traces can also overwhelm network infrastructure.
For this reason, teams sometimes use a strategy called sampling. Sampling means they collect only certain traces. The downside to sampling is that there’s a risk of missing important events, especially if problems occur intermittently and are therefore not represented in every request-response cycle.
One way to square this circle is leveraging hyper-efficient LLM tracing techniques, such as eBPF. Because eBPF-based tracing collects data via the Linux kernel, it uses minimal CPU and memory. This makes it feasible to trace most or all requests without overwhelming infrastructure.
LLM tracing for RAG pipelines and agent workflows
The basic principles behind LLM tracing are the same no matter which type of LLM-based workflow it involves. However, some special considerations come into play when tracing RAG pipelines and agentic AI workflows.
Tracing the retrieval-generation dependency chain
Tracing the retrieval-generation dependency chain in a retrieval-augmented generation (RAG) pipeline means capturing the sequence of operations that connect a user's query to the final LLM response.
An LLM trace should record each retrieval step, including query embedding, vector database searches, document ranking, context assembly, and the handoff of retrieved information to the language model. From there, it should capture the generation process, including the model invocation, token usage, latency, and response output.
Connecting these operations through parent-child spans within a single trace makes it possible for engineers to follow how information moves through the RAG pipeline, identify bottlenecks, and pinpoint failures such as poor retrieval quality, missing context, or unexpectedly slow generation.
Multi-step agent tracing: Loops, tool calls and reasoning steps
Multi-step agent tracing refers to capturing the sequence of decisions and operations that an AI agent performs to complete a task, including reasoning steps, tool calls, execution loops, and handoffs between agents or services.
Unlike a conventional LLM trace, which may capture a single model invocation, an agent trace must account for repeated model calls and branching workflows in which an agent evaluates intermediate results, selects tools, processes their outputs, and decides what to do next. Each operation should be recorded as a span linked to the larger trace, with metadata such as tool inputs and outputs, execution times, token usage, and model responses.
This allows engineers to reconstruct an agent's execution path, identify unnecessary loops or failed tool calls, diagnose errors, and understand why an agent produced a particular outcome.
What LLM tracing actually reveals when something goes wrong
Now that we’ve walked through how LLM tracing works, let’s say a bit more about why it’s so important.
The main reason is simple: LLM workflows are quite opaque by default. LLMs produce responses to prompts, but they typically include little, if any, information about why they generate a particular response.
This makes tracing critical for teams who need to know not just what an LLM is doing, but why it’s doing it. This insight is especially valuable given that LLM workflows often involve multiple steps and tools, making it difficult to judge, based on a response alone, exactly what the source of a problem is.
For example, imagine an LLM that is experiencing a high latency rate (meaning it’s taking a long time to generate responses). By generating spans and looking at which span takes the longest to execute, engineers might determine that an API call is holding up the response. From there, they could investigate the API to figure out whether the latency issue is linked to the way the API request is formatted, lack of sufficient resources on the endpoint hosting the API, buggy API behavior, or something else.
Where LLM tracing gets complicated in practice
LLM tracing tends to be relatively simple for teams dealing with just one or two LLMs, and with highly consistent types of prompts or workflows. It often becomes complicated as applications grow beyond simple, single-model interactions and introduce more complex workflows, distributed dependencies, and unpredictable execution paths.
RAG pipelines, multi-agent systems and tool-using agents also add complexity. They can generate deeply nested traces with hundreds of spans, making it difficult to reconstruct execution paths or identify the root cause of failures. Asynchronous operations, parallel tool calls, and retries further complicate the task of correlating events and establishing their execution order.
On top of this, teams must sometimes contend with high trace volumes, sampling trade-offs, instrumentation gaps, and the overhead of capturing large amounts of potentially sensitive prompt and response data.
Maintaining useful trace visibility therefore requires more than simply collecting spans. Engineers also need consistent instrumentation, meaningful context propagation, and tracing backends capable of handling complex workflows at scale.
Open source vs. proprietary LLM tracing tools
As LLM tracing has become a common component of modern observability strategies, a growing number of tools (including open source as well as proprietary options) have emerged to help collect LLM traces.
These two categories of tools offer different trade-offs around flexibility, control, deployment, and operational overhead:
- Open-source options (such as Langfuse, Arize Phoenix, LangSmith's open-source components and OpenTelemetry-based tracing) give engineering teams greater control over instrumentation, data handling and integration with existing observability infrastructure.
- Proprietary platforms (such as groundcover, Datadog and New Relic) typically offer managed tracing capabilities that can simplify deployment and integrate LLM telemetry with broader application and infrastructure monitoring.
The choice depends on factors such as data residency requirements (for example, it may be important to keep traces within a specific geographic region for compliance purposes, since spans may include regulated data like sensitive prompts), trace volume, customization needs, existing observability investments, and whether teams prefer to manage their own tracing infrastructure or rely on a vendor-hosted platform.
The habits that separate good LLM tracing from great LLM tracing
Generating LLM traces is easy enough with the right tools. But simply creating traces doesn’t guarantee excellent insights. Teams that trace as effectively as possible embrace practices like the following:
- Instrument every meaningful operation: Good LLM tracing captures model invocations and basic request metadata. Great tracing extends instrumentation to retrieval operations, tool calls, agent handoffs, retries, and other intermediate steps so engineers can reconstruct the entire execution path.
- Capture useful context without collecting unnecessary data: Include metadata such as model versions, token counts, latency, cost, and tool execution status. Avoid indiscriminately capturing sensitive prompts, responses, or user data that could introduce privacy and compliance risks.
- Connect traces to broader observability data: Correlate LLM traces with application logs, infrastructure metrics, distributed traces, and deployment events. This makes it easier to distinguish model-related problems from underlying application, network, or infrastructure failures.
- Use traces to drive continuous improvement: Don't limit tracing to reactive debugging. Analyze recurring patterns in latency, token consumption, retrieval quality, tool failures, and model outputs to identify optimization opportunities and prevent problems from recurring.
Full LLM trace visibility inside your own cloud with groundcover
groundcover can’t force your engineers to adopt highly impactful tracing practices. But it does solve many of the pain points of effective LLM tracing, including:
- Data residency and sovereignty requirements: With groundcover’s Bring Your Own Cloud (BYOC) architecture, every LLM trace view lives inside the customer's own environment. Sensitive data never touches third-party infrastructure or networks.
- Fidelity requirements: groundcover’s zero-sampling approach means teams see every span, every token cost, and every tool call, without being subject to vendor-side sampling decisions.
- Efficient resource usage: groundcover’s eBPF-based approach results in minimal resource overhead.
- Full-stack observability: groundcover complements LLM tracing data with metrics, logs, and traces from across the entire hosting stack. This means engineers can quickly distinguish LLM-specific issues from those triggered by infrastructure or application problems.

LLM tracing as a pillar of modern observability
In most business environments, LLMs are only as valuable as they are observable. After all, you can’t trust your LLMs, or optimize their cost and performance, if you don’t understand why they do the things they do.
Hence the vital role that LLM tracing plays in modern AI management strategies. Alongside other types of AI performance monitoring and observability, LLM traces provide critical insight that teams can’t obtain any other way.
FAQs
A trace represents the complete lifecycle of an LLM request or agent execution, while a span represents an individual operation within that lifecycle. The distinction matters because spans help isolate specific failures or bottlenecks within a larger workflow.
Head-based sampling makes sampling decisions when a trace begins. This reduces overhead but potentially misses errors that occur later. Tail-based sampling makes decisions after observing the full trace. It allows teams to retain problematic executions at the cost of greater processing and storage requirements.
groundcover's AI Trace Views presents LLM spans as AI-specific operations. It highlights details such as prompts, responses, model information, token usage, latency, and tool calls rather than treating them simply as generic application spans. It can also capture LLM traffic through its eBPF sensor without requiring changes to existing application instrumentation or high resource overhead.




