# Distributed tracing: What is it?

> Distributed tracing captures the timing and flow of requests, jobs, and AI agent runs across services, so you can debug where they fail or slow down. Learn how it works in Sentry.

**URL:** https://sentry.io/resources/what-is-distributed-tracing/

---

**Type:** Guide | **Date:** 2024-07-22T00:00:00.000Z

Distributed tracing captures the timing and flow of requests and operations as they happen in an application, across the frontend, the backend, and AI agents. In a modern architecture, a single user action can touch a frontend, several services, a queue, a database, a third-party API, and an LLM. Distributed tracing follows that work end to end, so you can see how it flowed, where it failed, and where it slowed down.

Tracing isn't only a performance tool. Every span in a trace shares a trace ID, and in Sentry that same ID connects errors, logs, session replays, and profiles. When an error happens, the trace gives you (or an agent) the full chain of events that led to it, not just the line that threw.

## What are the benefits of distributed tracing?

Development teams use [distributed tracing](https://docs.sentry.io/concepts/key-terms/tracing/distributed-tracing/) to debug problems that cross service boundaries: errors whose cause lives in another service, background jobs that fail quietly, agent runs that return the wrong answer, and requests that are slow for reasons no single service can explain.

### Reduce mean time to resolution

Modern applications depend on numerous microservices to exchange data and handle service requests across distributed systems. Debugging errors and slowdowns in such an architecture is much harder than in a monolith. In a microservices setup, the root cause of a problem might not be immediately apparent due to the complex interactions between various modules. Distributed tracing allows teams to monitor data as it traverses the intricate paths connecting multiple microservices and data storage units. By using distributed tracing tools, teams can track requests and visualize data propagation paths, so they can [find what went wrong](https://blog.sentry.io/distributed-tracing-inner-workings/) and reduce service disruptions quickly.

### Improve collaboration

Building a cloud application often involves several developers, each responsible for one or more microservices. The development process slows down when developers cannot trace the data exchanged between microservices. Distributed tracing systems provide telemetry data, such as logs and traces, for every service request a microservice makes. This transparency allows developers to collaborate more effectively, accurately address bugs, and resolve other issues discovered during testing and production.

### Ship faster

Organizations that deploy distributed tracing platforms can streamline and accelerate the release of software applications to end users. By reviewing distributed traces, software teams gain insights that speed up development, reduce costs, understand user behaviors, and enhance market readiness.

## How distributed tracing works

Imagine an online retail store with millions of customers. The store must track each customer's actions, such as browsing products, adding items to their cart, making purchases, and other interactions. Ensuring smooth operation would be unmanageable with traditional tracing methods, but distributed tracing makes it possible.

Distributed tracing monitors a request (transaction) as it moves between multiple services within a microservices architecture. This allows you to identify the origin of the service request (the user-facing frontend application) and follow its journey through other services.

Consider an example of distributed tracing in a typical modern online retail application consisting of multiple microservices:

1. A group of microservices manages the user interface, which displays the product catalog and handles user interactions.
2. User data, such as account information and order history, is recorded in a database service.
3. Several backend services handle tasks like inventory management, payment processing, and shipping.

In this environment, a distributed trace of the user's request would start by recording information about the request's status on the first frontend service, including the data the user inputs and the time it takes for the service to forward that data to other services.

The next step in the trace involves the backend services, which process tasks such as verifying inventory, processing payments, and initiating shipping. Finally, the backend services transfer the processed data to the database service, which stores it.

If the payment service throws an error, the trace shows you which user action triggered it, what the upstream services sent, and which downstream calls never happened. If checkout is slow, the same trace shows which span took the time.

## Tracing AI agents

AI agents are distributed systems too. A single agent run can call several models, execute tools, hand off to sub-agents, and hit your own APIs and databases along the way. When an agent returns a bad answer, there's often no error to look at.

Agent tracing follows one agent run from the system prompt to the final output and captures every model call, tool execution, and handoff as a span, along with inputs, outputs, token usage, and cost. Because those spans sit inside the same trace as your HTTP, database, and queue spans, a bad agent response leads straight back to the tool that quietly failed or the slow query behind it.

## The challenges of distributed tracing

Distributed tracing has made it much easier for developers to diagnose, debug, and fix software issues. However, there are still some challenges that software teams need to be aware of when choosing tracing tools.

### Manual instrumentation

Some tracing tools require developers to manually add code to generate the necessary traces. This process can introduce coding errors that affect production releases. Additionally, the lack of automation can make tracing more complicated, leading to delays and potentially inaccurate data collection.

### Limited frontend coverage

If tracing tools are limited to backend analysis, developers might not get a complete picture of what went wrong. In some cases, the distributed tracing system only starts collecting data when the first backend service receives the request. This means problems originating from frontend services during the user session can go undetected

### Random sampling

Some tools don't allow teams to prioritize which traces to collect, limiting observability to randomly sampled traces. With a limited sample size, organizations may need additional troubleshooting methods to capture major issues that the tracing tool might miss.

## Distributed tracing with Sentry

With Sentry's [distributed tracing](https://sentry.io/product/tracing/), you can follow the complete path of a request, job, or agent run from the originating user interaction across systems and services, and pinpoint the specific function, API call, or tool call causing the problem.

### Connected to everything else in Sentry

Errors, logs, session replays, metrics, and profiles share the same trace ID. Jump from an error to the span that produced it, from a replay to the backend request behind a broken click, or from a log line to the trace it belongs to.

### Agent tracing

[Agent tracing](https://sentry.io/product/tracing/ai-agent/) captures model calls, tool executions, sub-agent handoffs, token usage, and cost as spans inside your existing traces, so you can see what your agents did and where they broke.

### Automatic Instrumentation

Set up tracing in minutes. Just [follow the instructions](https://docs.sentry.io/platform-redirect/?original_referrer=https://sentry.io/&next=/tracing) in our docs to start sending spans. Or [watch the video](https://www.youtube.com/watch?v=fKmXCrChW70) to see how to set it up in less than 4 minutes.

### Best-in-class frontend support

Sentry partners directly with framework authors to build industry-leading support for React and React-related frameworks (e.g., [Javascript](https://docs.sentry.io/platforms/javascript/), [React Native](https://docs.sentry.io/platforms/react-native/)). You can trace a frontend error or slowdown back to the failing API call or slow database query behind it, across all your services.

### Sampling controls

When you enable sampling in your tracing setup, you choose a percentage of collected transactions to send to Sentry. For example, if you had an endpoint that received 1000 requests per minute, a sampling rate of 0.25 would result in approximately 250 transactions (25%) being sent to Sentry each minute.

> With a tracing solution that captures the entire request lifecycle across services, understanding a traffic spike now takes minutes, saving my team an average of 3 hours per issue.

*Ben Ogle, Founder, Anvil Foundry*

### Additional distributed tracing resources

- [Cookbook: Route OpenTelemetry Traces to Sentry](https://sentry.io/cookbook/route-opentelemetry-traces-to-sentry/)
- [Debugging Errors Faster with Distributed Tracing](https://sentry.io/resources/debugging-errors-faster-with-distributed-tracing/)
- [Distributed Tracing | Debugging your Next.js applications with Sentry](https://www.youtube.com/watch?v=L1cJgs5RZK0&list=PLOwEowqdeNMqf3dArAE-Mo4rVR7T2Vanr&index=6&t=3s)
- [Frontend issues with backend solutions](https://www.youtube.com/watch?v=-I872moWyB0)
- [Tracing docs](https://docs.sentry.io/concepts/key-terms/tracing/)
- [Agent tracing docs](https://docs.sentry.io/concepts/key-terms/agent-tracing/)

---

*Source: [sentry.io/resources/what-is-distributed-tracing/](https://sentry.io/resources/what-is-distributed-tracing/)*
