Skip to content

Commit eed3973

Browse files
fix(rn): tracePropagationTargets differs on mobile and web in RN v6 (#11579)
1 parent 12b6f30 commit eed3973

File tree

5 files changed

+12
-27
lines changed

5 files changed

+12
-27
lines changed

docs/platforms/react-native/configuration/options.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ The option may contain a list of strings or regex against which the URLs of outg
267267
If one of the entries in the list matches the URL of an outgoing request, trace data will be attached to that request.
268268
String entries do not have to be full matches, meaning the URL of a request is matched when it _contains_ a string provided through the option.
269269

270-
If <PlatformIdentifier name="trace-propagation-targets" /> is not provided, trace data is only attached to outgoing requests that contain `localhost` in their URL or requests whose URL starts with a `'/'` (for example `GET /api/v1/users`).
270+
If <PlatformIdentifier name="trace-propagation-targets" /> is not provided, trace data is attached to every outgoing request from the application (mobile, desktop, tv). When running on web trace data is only attached to outgoing requests that contain `localhost` in their URL or requests whose URL starts with a `'/'` (for example `GET /api/v1/users`).
271271

272272
</ConfigKey>
273273

docs/platforms/react-native/tracing/instrumentation/automatic-instrumentation.mdx

+8-1
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,19 @@ Sentry.init({
112112

113113
### tracePropagationTargets
114114

115-
The default value of `tracePropagationTargets` is `['localhost', /^\//]`. The React Native SDK will attach the `sentry-trace` header to all outgoing XHR/fetch requests whose destination contains a string in the list or matches a regex in the list. If your frontend is making requests to a different domain, you'll need to add the domain there to propagate the `sentry-trace` header to the backend services, which is required to link transactions together as part of a single trace. **The `tracePropagationTargets` option matches against the entire request URL, not just the domain. Using stricter regex to match certain parts of the URL ensures that requests don't unnecessarily have the `sentry-trace` header attached.**
115+
The default value of `tracePropagationTargets` is `[/.*/]` for mobile and `['localhost', /^\//]` for web. The React Native SDK will attach the `sentry-trace` header to all outgoing XHR/fetch requests on mobile.
116+
On web, trace data is only attached to outgoing requests that contain `localhost` in their URL or requests whose URL starts with a `'/'` (for example `GET /api/v1/users`).
117+
118+
<Expandable title="Using React Native on Web? Here is how `tracePropagationTargets` changes.">
119+
120+
The SDK will attach the `sentry-trace` header to all outgoing XHR/fetch requests whose destination contains a string in the list or matches a regex in the list. If your frontend is making requests to a different domain, you'll need to add the domain there to propagate the `sentry-trace` header to the backend services, which is required to link transactions together as part of a single trace. **The `tracePropagationTargets` option matches against the entire request URL, not just the domain. Using stricter regex to match certain parts of the URL ensures that requests don't unnecessarily have the `sentry-trace` header attached.**
116121

117122
<PlatformContent includePath="performance/tracePropagationTargets-example" />
118123

119124
You'll need to configure your web server CORS to allow the `sentry-trace` header. The configuration might look like `"Access-Control-Allow-Headers: sentry-trace"`, but the configuration depends on your setup. If you don't allow the `sentry-trace` header, the request might get blocked.
120125

126+
</Expandable>
127+
121128
### beforeStartSpan
122129

123130
`beforeStartSpan` is called at the start of every `pageload` or `navigation` span, and is passed an object containing data about the span which will be started. With `beforeStartSpan` you can modify that data.

docs/platforms/react-native/tracing/instrumentation/expo-router.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The code snippet below shows how to initialize the instrumentation.
1313
```javascript {6-8, 15-16, 20-25} {filename: app/_layout.tsx}
1414
import React from 'react';
1515
import { Slot, useNavigationContainerRef } from 'expo-router';
16-
import Constants, { ExecutionEnvironment.StoreClient } from 'expo-constants';
16+
import Constants, { ExecutionEnvironment } from 'expo-constants';
1717
import * as Sentry from '@sentry/react-native';
1818

1919
const navigationIntegration = Sentry.reactNavigationintegration({

platform-includes/performance/enable-tracing/react-native.mdx

-17
This file was deleted.

platform-includes/performance/tracePropagationTargets-example/react-native.mdx

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@ For example:
33
- A frontend application is served from `example.com`
44
- A backend service is served from `api.example.com`
55
- The frontend application makes API calls to the backend
6-
- Therefore, the option needs to be configured like this: `new Sentry.ReactNativeTracing({tracePropagationTargets: ['api.example.com']})`
6+
- Therefore, the option needs to be configured like this: `Sentry.init({tracePropagationTargets: ['api.example.com']})`
77
- Now outgoing XHR/fetch requests to `api.example.com` will get the `sentry-trace` header attached
88

9-
109
```javascript
1110
Sentry.init({
1211
dsn: "___PUBLIC_DSN___",
13-
integrations: [
14-
new Sentry.ReactNativeTracing({
15-
tracePropagationTargets: ["localhost", "my-site-url.com"],
16-
}),
17-
],
12+
tracePropagationTargets: ["localhost", "my-site-url.com"],
1813

1914
// We recommend adjusting this value in production, or using tracesSampler
2015
// for finer control

0 commit comments

Comments
 (0)