Sentry Setup
Sentry is one of the most popular solution for error reporting in the javascript ecosystem and has a great integration with Expo, we have been using it for a while and it has been working very well.
The starter kit did not come with Sentry pre-configured, but it’s very easy to setup and this guide will walk you through the process.
Install and configure Sentry
-
Create a new Sentry account if you don’t have one already. Once logged in, create a new project for your React Native app.
-
During project creation, pay close attention to and note down the following important details:
-
Organization slug
-
Project name
-
DSN
we will use those details next to configure the Sentry SDK in your app.
-
-
Now you need also to generate a new Auth Token so you can use it to upload source maps to Sentry. To generate a new Auth Token you need to go to Developer Settings > Auth Tokens and create a new token.
- Copy and securely store the generated token. You’ll need this for configuring source map uploads.
-
At this point, you should have the following environment variables that need to be added to your
.env
files:It’s crucial to add these variables to
env.js
for validation.SENTRY_ORG
andSENTRY_PROJECT
should be added as build-time variables, whileSENTRY_DSN
should be added as a client variable.Update your
env.js
file as follows: -
Now you can install the Sentry SDK in your project.
-
Add Sentry plugin config to your
app.config.ts
file. -
Update your metro config to inject debug ID intro your source maps
-
Now you are ready to initialize Sentry in your app. Create a new file
src/lib/sentry.ts
and add the following code:Then, initialize Sentry and configure it with navigation in your
src/app/_layout.tsx
file:This setup will enable Sentry error tracking and performance monitoring in your app.
-
One last thing is to add Apple privacy manifest to prevent any issues with Apple. Create a new file
apple-privacy-manifest.json
and add the following code:Then add it to your
app.config.ts
Read more about Apple Privacy Manifest and sentry
-
Now you are ready to test Sentry integration. Follow these steps to ensure errors are being reported correctly:
- Run the prebuild command for your project.
- Launch the app in a simulator or on a physical device.
- Use the following code snippet to add error-triggering buttons to your app:
- Implement this component in your app and interact with the buttons.
- Check your Sentry dashboard to verify that the errors are being reported correctly (make sure to wait a little bit for the errors to appear).
Remember to remove or disable these test buttons before releasing your app to production.