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
feat(react-native): React Native auto performance docs (#2908)
* wip: Just write out what needs to be mentioned for RN auto perf
* ref: Update tracing import
* feat: Split up JS and RN auto instrumentation page, and write up.
* ref: Code review suggestions
Co-authored-by: Fiona <[email protected]>
Co-authored-by: Fiona <[email protected]>
To _automatically_ capture transactions, you must first <PlatformLinkto="/performance/">enable tracing in your app.</PlatformLink>
@@ -47,3 +50,220 @@ For `pageload` and `navigation` transactions, the `BrowserTracing` integration u
47
50
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`.
Automatic instrumentation is currently in beta, available on the Sentry React Native SDK version ≥ 2.2.0-beta.0. As a result, the API may change without warning.
60
+
</Alert>
61
+
62
+
`@sentry/react-native` provides a `ReactNativeTracing` integration to add _automatic_ instrumentation for monitoring the performance of React Native applications.
63
+
64
+
## What Automatic Instrumentation Provides
65
+
66
+
The `ReactNativeTracing` integration 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/).
67
+
68
+
## Enable Automatic Instrumentation
69
+
70
+
To enable automatic tracing, include the `ReactNativeTracing` integration in your SDK configuration options.
// We recommend adjusting this value in production, or using tracesSampler
86
+
// for finer control
87
+
tracesSampleRate:1.0,
88
+
});
89
+
```
90
+
91
+
Next, instrument your app with [routing instrumentation](#enable-routing-instrumentation).
92
+
93
+
## Configuration Options
94
+
95
+
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).
96
+
97
+
### tracingOrigins
98
+
99
+
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 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 `tracingOrigins` option matches against the entire 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 setup. If you do not allow the `sentry-trace` header, the request might be blocked.
104
+
105
+
### shouldCreateSpanForRequest
106
+
107
+
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 except what was defined in `tracingOrigins`.
We currently provide two routing instrumentations out of the box to instrument route changes for React Navigation V5 and V4. In the future, we will add support for other libraries such as [react-native-navigation](https://github.com/wix/react-native-navigation). Otherwise, if you have a custom routing instrumentation, or use a routing library we don't yet support, you can use the bare bones routing instrumentation or create your own by extending it.
114
+
115
+
### React Navigation V5
116
+
117
+
Note that this routing instrumentation will create a transaction on every route change including `goBack` navigations.
118
+
119
+
```js
120
+
import*asSentryfrom"@sentry/react-native";
121
+
122
+
// Construct a new instrumentation instance. This is needed to communicate between the integration and React
### Other Routing Libraries or Custom Routing Implementations
190
+
191
+
If you use another routing library that we don't yet support, or have a custom routing solution, you can use the basic `RoutingInstrumentation` we provide, or extend it to create your own instrumentation.
192
+
193
+
Every routing instrumentation revoles around one method:
// Again, ensure this is called BEFORE the route changes and BEFORE the route is mounted.
241
+
this.onRouteWillChange({
242
+
name:newRoute.name,
243
+
op:"navigation",
244
+
});
245
+
}
246
+
}
247
+
```
248
+
249
+
## Recipes
250
+
251
+
Currently, by default, the React Native SDK will only create child spans for fetch/XHR transactions out of the box. This means once you are done setting up your routing instrumentation, you will either see just a few fetch/XHR child spans or no children at all. To find out how to manually instrument your app, review our <PlatformLinkto="/performance/capturing/manual/">Manual Instrumentation</PlatformLink>.
252
+
253
+
### React Profiler
254
+
255
+
We export the React Profiler from our React Native SDK as well, you can read more at [React Profiler](/platforms/javascript/guides/react/components/profiler/).
256
+
257
+
After you instrument your app's routing, if you wrap a component that renders on one of the routes with `withProfiler`, you will be able to track the component's lifecycle as a child span of the route transaction.
0 commit comments