Skip to content

Commit 78571cb

Browse files
feat(rn): Add Expo Router auto instrumentation guide (#9501)
Co-authored-by: vivianyentran <[email protected]>
1 parent 75b4da0 commit 78571cb

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

docs/platforms/react-native/manual-setup/expo.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ To verify that everything is working as expected, build the `Release` version of
100100
## Next Steps
101101

102102
- [Learn how to upload source maps for native builds and Expo Updates](/platforms/react-native/sourcemaps/uploading/expo/)
103+
- [Add automatic performance monitoring with Expo Router](/platforms/react-native/performance/instrumentation/expo-router/)
103104

104105
## Notes
105106

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ We currently provide three routing instrumentations out of the box to instrument
3131
- [React Navigation](/platforms/react-native/performance/instrumentation/react-navigation/)
3232
- [React Navigation V4 and prior](/platforms/react-native/performance/instrumentation/react-navigation-v4/)
3333
- [React Native Navigation](/platforms/react-native/performance/instrumentation/react-native-navigation/)
34+
- [Expo Router](/platforms/react-native/performance/instrumentation/expo-router/)
3435
- [Custom Instrumentation](/platforms/react-native/performance/instrumentation/custom-navigation/), implement automatic navigation instrumentation for a custom library.
3536

3637
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](#bare-bones) or [create your own](#custom-instrumentation) by extending it.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Expo Router
3+
description: "Learn how to use Sentry's Expo Router instrumentation."
4+
sidebar_order: 65
5+
---
6+
7+
Sentry's React Native SDK package ships with instrumentation for Expo Router. This allows you to see the performance of your navigation transitions and the errors that occur during them. This page will guide you through setting up the instrumentation and configuring it to your needs.
8+
9+
## Initialization
10+
11+
The code snippet below shows how to initialize the instrumentation.
12+
13+
```javascript { filename: 'app/_layout.tsx' }
14+
import React from 'react';
15+
import { Slot, useNavigationContainerRef } from 'expo-router';
16+
import Constants from 'expo-constants';
17+
import * as Sentry from '@sentry/react-native';
18+
19+
const routingInstrumentation = new Sentry.ReactNavigationInstrumentation({
20+
enableTimeToInitialDisplay: Constants.appOwnership !== 'expo', // Only in native builds, not in Expo Go.
21+
});
22+
23+
Sentry.init({
24+
dsn: '___PUBLIC_DSN___',
25+
integrations: [
26+
new Sentry.ReactNativeTracing({
27+
routingInstrumentation,
28+
enableNativeFramesTracking: Constants.appOwnership !== 'expo', // Only in native builds, not in Expo Go.
29+
}),
30+
],
31+
});
32+
33+
function RootLayout() {
34+
const ref = useNavigationContainerRef();
35+
36+
React.useEffect(() => {
37+
if (ref) {
38+
routingInstrumentation.registerNavigationContainer(ref);
39+
}
40+
}, [ref]);
41+
42+
return <Slot />;
43+
}
44+
45+
export default Sentry.wrap(RootLayout);
46+
```
47+
48+
## Options
49+
50+
You can configure the instrumentation by passing an options object to the constructor:
51+
52+
```javascript
53+
new Sentry.ReactNavigationInstrumentation({
54+
enableTimeToInitialDisplay: true, // default: false
55+
routeChangeTimeoutMs: 1000, // default: 1000
56+
});
57+
```
58+
59+
### routeChangeTimeoutMs
60+
61+
This option specifies how long the instrumentation will wait for the route to mount after a change has been initiated before the transaction is discarded. The default value is 1000ms.
62+
63+
### enableTimeToInitialDisplay
64+
65+
This option will enable automatic measuring of the time to initial display for each route. To learn more see [Time to Initial Display](/platforms/react-native/performance/instrumentation/time-to-display).
66+
67+
## Notes
68+
69+
- Slow and Frozen frames, Time To Initial Display and Time To Full Display are only available in native builds, not in Expo Go.

0 commit comments

Comments
 (0)