---
title: "Trace Propagation"
description: "Learn how to connect events across applications/services."
url: https://docs.sentry.io/platforms/android/tracing/trace-propagation/
---

# Trace Propagation | Sentry for Android

If the overall application landscape that you want to observe with Sentry consists of more than just a single service or application, distributed tracing can add a lot of value.

## [What is Distributed Tracing?](https://docs.sentry.io/platforms/android/tracing/trace-propagation.md#what-is-distributed-tracing)

In the context of tracing events across a distributed system, distributed tracing acts as a powerful debugging tool. Imagine your application as a vast network of interconnected parts. For example, your system might be spread across different servers or your application might split into different backend and frontend services, each potentially having their own technology stack.

When an error or performance issue occurs, it can be challenging to pinpoint the root cause due to the complexity of such a system. Distributed tracing helps you follow the path of an event as it travels through this intricate web, recording every step it takes. By examining these traces, you can reconstruct the sequence of events leading up to the event of interest, identify the specific components involved, and understand their interactions. This detailed visibility enables you to diagnose and resolve issues more effectively, ultimately improving the reliability and performance of your distributed system.

## [Basic Example](https://docs.sentry.io/platforms/android/tracing/trace-propagation.md#basic-example)

Here's an example showing a distributed trace in Sentry:

This distributed trace shows a Vue app's `pageload` making a request to a Python backend, which then calls the `/api` endpoint of a Ruby microservice.

What happens in the background is that Sentry uses reads and further propagates two HTTP headers between your applications:

* `sentry-trace`
* `baggage`

If you run any JavaScript applications in your distributed system, make sure that those two headers are added to your CORS allowlist and won't be blocked or stripped by your proxy servers, gateways, or firewalls.

## [How to Use Distributed Tracing?](https://docs.sentry.io/platforms/android/tracing/trace-propagation.md#how-to-use-distributed-tracing)

For Sentry Android SDK versions `6.25.x` and higher, distributed tracing works out of the box for any HTTP request sent with OkHttp, Apollo, or Apollo 3, if the integration for it is enabled. If you use SDK version `6.24.x` or below, you need to follow the [Custom Instrumentation](https://docs.sentry.io/platforms/android/tracing/trace-propagation/custom-instrumentation.md) set up steps.

Remember that in order to propagate trace information through your whole distributed system, you have to use Sentry in all of the involved services and applications. Take a look at the respective SDK documentation to learn how distributed tracing can be enabled for each platform.

### [tracePropagationTargets](https://docs.sentry.io/platforms/android/tracing/trace-propagation.md#tracepropagationtargets)

The Android SDK will attach the `sentry-trace` and `baggage` headers to all outgoing requests by default. To narrow this down to only specific URLs, add those URLs to the `tracePropagationTargets` allowlist, (you can use both strings and regexes). The SDK will then only attach the `sentry-trace` and `baggage` headers to outgoing requests matching the allowlist.

The `tracePropagationTargets` option can contain full URLs (e.g. `"https://api.myproject.org/request/path"`), sub-strings (e.g. `"api.myproject.org"`) or regular expressions (e.g. `"https://[\w]*\.myproject\.org/.*"`).

Since the value of `tracePropagationTargets` is `".*"` by default, tracing headers are attached to all requests unless otherwise specified.

```java
SentryAndroid.init(context, options -> {
    final ArrayList<String> tracePropagationTargets = new ArrayList<>();
    tracePropagationTargets.add("https://api.myproject.org/");

    options.setDsn("___PUBLIC_DSN___");
    options.setTracePropagationTargets(tracePropagationTargets);
});
```

## [W3C Traceparent Header Support](https://docs.sentry.io/platforms/android/tracing/trace-propagation.md#w3c-traceparent-header-support)

Starting from version 8.22.0, the Java SDK also supports the W3C `traceparent` HTTP header for outgoing requests. This header follows the [W3C Trace Context specification](https://develop.sentry.dev/sdk/telemetry/traces/distributed-tracing/#w3c-trace-context-header) and provides interoperability with other tracing systems that support this standard.

To enable W3C `traceparent` header propagation, set the [`propagateTraceparent`](https://docs.sentry.io/platforms/android/configuration/options.md#propagateTraceparent) option to `true`. When enabled, the `traceparent` header will be propagated alongside the `sentry-trace` and `baggage` headers to outgoing HTTP requests. Like the other headers, it's attached to all requests by default, or only to requests matching your `tracePropagationTargets` configuration if you've specified one.

## Pages in this section

- [Custom Instrumentation](https://docs.sentry.io/platforms/android/tracing/trace-propagation/custom-instrumentation.md)
- [Dealing with CORS Issues](https://docs.sentry.io/platforms/android/tracing/trace-propagation/dealing-with-cors-issues.md)
