# Distributed tracing with Better Stack

<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
  <iframe 
    style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" 
    src="https://www.youtube.com/embed/7tQ7haFmSXI" 
    title="YouTube video player" 
    frameborder="0" 
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" 
    referrerpolicy="strict-origin-when-cross-origin" 
    allowfullscreen>
  </iframe>
</div>

Distributed tracing allows you to follow a single request as it travels through all the different microservices and components of your system.

By visualizing the entire journey of a request in one place, you can instantly pinpoint performance bottlenecks, identify errors, and understand the complex interactions within your application.

![Tracing in Live tail](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/94185e85-b6e1-4ab9-4809-3ff5e931f100/md2x =4160x2378)

**Better Stack unifies logs, metrics, and traces**, the three pillars of observability, into a single platform. This means you can seamlessly navigate from a slow trace to the exact logs and metrics generated during that request, giving you the full context you need to resolve issues faster.

[info]
#### Is this your first time working with distributed tracing?
Start with our [Distributed Tracing guide](https://betterstack.com/community/guides/observability/distributed-tracing/) for a general overview.
[/info]

## Getting started

Better Stack ingests trace data using the OpenTelemetry Protocol (OTLP), the open standard for telemetry data. The easiest way to send traces is by using the [Better Stack collector](https://betterstack.com/docs/logs/collector/) or configuring [OpenTelemetry](https://betterstack.com/docs/logs/open-telemetry/) directly.

Once your traces arrive, you can explore them in [Logs & traces](https://telemetry.betterstack.com/team/0/tail ";_blank"). Just make sure to select a source marked as `spans`.

![Start by choosing a span source](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/9edd9356-c97b-4c25-db8a-032172fba000/lg2x =3464x1454)

## Exploring traces

The main view provides a list of recent traces, allowing you to quickly see the most important information at a glance.

![Trace and span details](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/3081c8c3-7070-485a-39e8-b426c2abdd00/md2x =4160x2450)

Clicking on any trace will take you to the detailed trace view, which displays a waterfall chart of all the spans within that trace. You can expand further details by clicking on the spans within. This visualization helps you understand the timing and parent-child relationships between different operations.

## Filtering traces and spans

From [Logs & traces](https://telemetry.betterstack.com/team/0/tail ";_blank"), you can search and filter traces for example by:

*   **Service name**
*   **Operation name** - e.g. `HTTP GET /users/:id`
*   **Latency** - duration
*   **Status** - success or error
*   **Custom tags and attributes**

In the **Attributes** tab, you can hover over or click on individual spans to inspect their metadata, including HTTP status codes, database queries, and any custom attributes you've added.

![Filtering by attributes in Tracing](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/918844fe-4b40-42c6-94a4-d09568eb9500/orig =4160x2012)

You can use the [Live tail query language](https://betterstack.com/docs/logs/using-logtail/live-tail-query-language/) for matching your spans.

## Correlate traces with logs and metrics

The real power of Better Stack lies in its ability to connect traces with logs and metrics automatically. When your logs and traces include the same `trace_id`, Better Stack links them together.

From the trace detail view, you can instantly pivot to the logs associated with a specific span or the entire trace in the **Logs & events**. This gives you the full context needed for debugging, showing you the exact log messages generated during that request.

This unified view eliminates the need to manually search for logs that match a specific request, saving you valuable time during an incident.

[note]
#### Can't see your logs linked to your traces?

To enable automatic correlation, ensure that your logs and traces include the same `span.trace_id` and `span.span_id` fields, that their timestamps fall within the span's duration, and that your logs and traces are being sent into the same telemetry source.

If your logs use different field names (like `trace_id` or `context.trace_id`), or if the [timestamp field](https://betterstack.com/docs/logs/ingesting-data/http/#sending-timestamps) is not correctly mapped to `.dt`, use a [VRL transformation](https://betterstack.com/docs/logs/using-logtail/transforming-ingested-data/logs-vrl/) on your source to rename them or map the correct timestamp upon ingest.

For example, using `.span.trace_id = del(.context.trace_id)` or `.dt = del(.timestamp)`.
[/note]

## Collaborate with colleagues

Similarly as with your logs or incident, you can add comments to whole traces or even spans in the **Comments** tab.

Use `@` to mention your team mates, making sure they get notified about it.

## AI-powered summaries

You can use the built-in LLM to summarize the trace or span for you - try it out by accessing the **Explain with AI** tab!

![Span detail and Explain with AI](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/6913c2c2-9668-42b3-9c23-b6e707ff1e00/public =4160x1704)

## Use cases

### Pinpoint performance bottlenecks
Use the waterfall view to identify which service, database query, or API call is taking the longest. The visual breakdown makes it easy to spot inefficiencies in your system.

### Debug errors in microservices
When an error occurs, a trace can show you the exact path the request took and which service returned the error. By correlating this with logs, you can see the error message and stack trace, leading to a faster resolution.

### Understand system behavior
Visualize the end-to-end flow of requests to understand how your services interact. This is invaluable for onboarding new engineers, refactoring code, or planning new features.

## Need help?

Please let us know at hello@betterstack.com. We're happy to help! 🙏
