You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn how to add automatic instrumentation to captured transactions."
7
8
---
8
9
@@ -12,38 +13,251 @@ To _automatically_ capture transactions, you must first <PlatformLink to="/perfo
12
13
13
14
</Note>
14
15
15
-
The `@sentry/tracing` package provides a `BrowserTracing` integration to add _automatic_ instrumentation for monitoring the performance of browser applications.
16
+
The `@sentry/react-native`provides a `ReactNativeTracing` integration to add _automatic_ instrumentation for monitoring the performance of React Native applications.
16
17
17
18
## What Automatic Instrumentation Provides
18
19
19
-
The `BrowserTracing` integration creates a new transaction for each page load and navigation event, and creates a child span for every `XMLHttpRequest` or `fetch` request that occurs while those transactions are open. Learn more about [traces, transactions, and spans](/product/performance/distributed-tracing/).
20
+
The `ReactNativeTracing`creates a child span for every `XMLHttpRequest` or `fetch` request on the Javascript layer that occurs while those transactions are open. Learn more about [traces, transactions, and spans](/product/performance/distributed-tracing/).
20
21
21
22
## Enable Automatic Instrumentation
22
23
23
-
To enable this automatic tracing, include the `BrowserTracing` integration in your SDK configuration options. (Note that when using ESM modules, the main `@sentry/*` import must come before the `@sentry/tracing` import.)
24
+
To enable this automatic tracing, include the `ReactNativeTracing` integration in your SDK configuration options.
// We recommend adjusting this value in production, or using tracesSampler
40
+
// for finer control
41
+
tracesSampleRate:1.0,
42
+
});
43
+
```
26
44
27
45
## Configuration Options
28
46
29
-
You can pass many different options to the `BrowserTracing` integration (as an object of the form `{optionName: value}`), but it comes with reasonable defaults out of the box. For all possible options, see [TypeDocs](https://getsentry.github.io/sentry-javascript/interfaces/tracing.browsertracingoptions.html).
47
+
You can pass many different options to the `ReactNativeTracing` integration (as an object of the form `{optionName: value}`), but it comes with reasonable defaults out of the box. For all possible options, see [TypeDocs](https://getsentry.github.io/sentry-javascript/interfaces/tracing.browsertracingoptions.html).
30
48
31
49
### tracingOrigins
32
50
33
-
The default value of `tracingOrigins` is `['localhost', /^\//]`. The JavaScript 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 will need to add it 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 `tracingOrigins` option matches against the whole request URL, not just the domain. Using stricter regex to match certain parts of the URL ensures that requests do not unnecessarily have the `sentry-trace` header attached.**
51
+
The default value of `tracingOrigins` 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 will need to add it 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 `tracingOrigins` option matches against the whole request URL, not just the domain. Using stricter regex to match certain parts of the URL ensures that requests do not unnecessarily have the `sentry-trace` header attached.**
You will 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 set up. If you do not allow the `sentry-trace` header, the request might be blocked.
38
56
39
-
### beforeNavigate
40
-
41
-
For `pageload` and `navigation` transactions, the `BrowserTracing` integration uses the browser's `window.location` API to generate a transaction name. To customize the name of the `pageload` and `navigation` transactions, you can supply a `beforeNavigate` option to the `BrowserTracing` integration. This option allows you to modify the transaction name to make it more generic, so that, for example, transactions named `GET /users/12312012` and `GET /users/11212012` can both be renamed `GET /users/:userid`, so that they'll group together.
This function can be used to filter out unwanted spans such as XHR's running health checks or something similar. By default `shouldCreateSpanForRequest` already filters out everything but what was defined in `tracingOrigins`.
In our React Native, we currently provide two routing instrumentations out of the box for React Navigation V5 and V4. Otherwise you can use the bare bones routing instrumentation or create your own.
66
+
67
+
### React Navigation V5
68
+
69
+
Note that this routing instrumentation will create a transaction on every route change including `goBack` navigations.
70
+
71
+
```js
72
+
import*asSentryfrom"@sentry/react-native";
73
+
74
+
// Construct a new instrumentation instance. This is needed to communicate between the integration and React
// Note that it is route.routeName here and NOT route.name like in V5, this is directly from React-Navigation
181
+
if (route.routeName==='Ignore-Route') {
182
+
returnfalse;
183
+
}
184
+
185
+
if (route.params.containsSensitiveInfo) {
186
+
returnfalse;
187
+
}
188
+
189
+
if (previousRoute.name==='ShouldIgnoreAfter') {
190
+
returnfalse;
191
+
}
192
+
193
+
returntrue;
194
+
}
195
+
});
196
+
197
+
// ...
198
+
```
199
+
200
+
### Other Navigation Libraries or Custom Navigation
201
+
202
+
If you use another navigation library that we don't support or have a custom navigation solution, you can use our basic `RoutingInstrumentation` or extend it to create your own class.
203
+
204
+
Every routing instrumentation revoles around one method:
0 commit comments