Closed statico closed 4 months ago
In expo router, there is no entry point App.js, so no way to wrap it with sentry.
When adding Sentry.init
to my root layout using expo-router it seems to initiate multiple times as I'm getting
'http.client' span on transaction 'App Start'
In a loop. Some pointers on how to correctly implement sentry to expo-router would be much appreciated.
@statico I am facing the same issue right now. I tried your solution in my app, but I'm getting this error
Cannot read property 'isReady' of undefined
The difference I noticed between our setup is that I'm using SDK 49. Not sure if that is cause this error. I'm using an iOS device for testing. Is there any additional setup required for the solution you have implemented?
@prathmeshgodse We upgraded to Expo v49, but I just checked and the code is the same. No issues here.
Here's our package.json in case that helps:
〉jq '.dependencies' <package.json | egrep 'expo|sentry'
"@clerk/clerk-expo": "0.19.16",
"@expo/webpack-config": "19.0.0",
"@sentry/react": "7.73.0",
"@sentry/react-native": "5.10.0",
"expo": "49.0.13",
"expo-application": "5.4.0",
"expo-auth-session": "5.2.0",
"expo-av": "13.6.0",
"expo-camera": "13.6.0",
"expo-clipboard": "4.5.0",
"expo-constants": "14.4.2",
"expo-contacts": "12.4.0",
"expo-crypto": "12.6.0",
"expo-dev-client": "2.4.11",
"expo-device": "5.6.0",
"expo-document-picker": "11.7.0",
"expo-file-system": "15.6.0",
"expo-font": "11.6.0",
"expo-haptics": "12.6.0",
"expo-image": "1.5.1",
"expo-image-manipulator": "11.5.0",
"expo-image-picker": "14.5.0",
"expo-linear-gradient": "~12.3.0",
"expo-linking": "5.0.2",
"expo-localization": "14.5.0",
"expo-location": "16.3.0",
"expo-media-library": "15.6.0",
"expo-network": "5.6.0",
"expo-notifications": "0.20.1",
"expo-router": "2.0.8",
"expo-secure-store": "12.5.0",
"expo-sharing": "11.7.0",
"expo-splash-screen": "0.20.5",
"expo-status-bar": "1.7.1",
"expo-store-review": "6.6.0",
"expo-task-manager": "11.5.0",
"expo-updates": "0.18.14",
"sentry-expo": "7.0.1",
Hey @statico, I made a small mistake. Moved your code snippet within the layout default export and now it works. Thanks for your reply!
On a side note, were you able to enable profiling for your app? I have tried wrapping my components with Sentry.Native.withProfiler
but I do not get any profiling metrics.
This is my init
code snippet
Sentry.init({
dsn: DNS,
enableInExpoDevelopment: true, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
tracesSampleRate: 1.0,
debug: false,
_experiments: {
profileSampleRate: 1.0
}
});
Hello everyone,
@sentry/react-native
now supports Expo out of the box!
See the new documentation for expo-router
https://docs.expo.dev/guides/using-sentry/#usage-with-expo-router
Update to https://github.com/getsentry/sentry-react-native/releases/tag/5.16.0 or newer to get all the new features.
Migration guides available:
This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.
This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.
Summary
If you're using sentry-expo, you might also be using expo-router since you're part of the Expo ecosystem.
Unfortunately, I had trouble getting this to work with expo-router and had to write my own solution. It looks like this, which I have in our top-level
_layout.tsx
component:Managed or bare workflow? If you have
ios/
orandroid/
directories in your project, the answer is bare!managed
What platform(s) does this occur on?
iOS
SDK Version (managed workflow only)
48
Environment
Also:
Reproducible demo or steps to reproduce from a blank project
npx expo install
the usual stuff includingsentry-expo
andexpo-router
enableInExpoDevelopment
anddebug
are trueintegrations: [new Sentry.Native.ReactNativeTracing({ ... })]
to the Sentry initroutingInstrumentation
andSentry.Native.ReactNavigationInstrumentation
You may experience the infinite loop in #368 — in which case, add
enableAppStartTracking: false
You'll find that the first route starts a transaction, but changing to any route doesn't start a transaction.