Streamline Error Tracking in React Native with Expo and Sentry
Catching errors in React Native is critical for maintaining a smooth user experience. Let’s face it, we’ve all had bugs slip into…

Catching errors in React Native is critical for maintaining a smooth user experience. Let’s face it, we’ve all had bugs slip into production. With Sentry, you can easily track and resolve these errors in your Expo applications. Here’s how to integrate Sentry for enhanced error management.
Step 1: Set Up Your Sentry Account
- Sign Up for Sentry: Create an account if you haven’t already.
- Create a Project: Navigate to your dashboard and set up a new project. Note your organization slug and project name for later configuration.
Step 2: Install the Sentry SDK
- Run the following command in your project directory:
npx expo install @sentry/react-native
Step 3: Configure Your App
- Add the Config Plugin: Update your app.json or app.config.js:
{
"expo": {
"plugins": [
[
"@sentry/react-native/expo",
{
"organization": "sentry org slug, or use the `SENTRY_ORG` environment variable",
"project": "sentry project name, or use the `SENTRY_PROJECT` environment variable",
"url": "https://sentry.io/"
}
]
]
}
}
- organization slug is available in your Organization settings tab
- project name is available in your project’s Settings > Projects tab (find it in the list)
Step 4: Set Environment Variables
- SENTRY_AUTH_TOKEN: From your Sentry dashboard, create an Organization Auth Token under Developer Settings > Auth Tokens. Add this token to your .env file:
SENTRY_AUTH_TOKEN="Your Auth Token"
Step 5: Update Metro Configuration
- Modify your metro.config.js for source map handling:
const { getSentryExpoConfig } = require('@sentry/react-native/metro');
const config = getSentryExpoConfig(__dirname);
module.exports = config;
Step 6: Initialize Sentry in Your Application
- In your main app file (e.g., App.tsx or index.js):
import * as Sentry from '@sentry/react-native';
Sentry.init({
dsn: 'YOUR DSN HERE',
debug: true, // Set to false for production
});
- DSN: Obtain from your project’s settings in Sentry.
Step 7: Integrate with Navigation
- React Navigation:
import * as Sentry from '@sentry/react-native';
const App = () => {
// Your app components here
};
export default Sentry.wrap(App);
- Expo Router: Add to _layout.tsx:
import { Slot, useNavigationContainerRef } from 'expo-router';
import { useEffect } from 'react';
import * as Sentry from '@sentry/react-native';
import { isRunningInExpoGo } from 'expo';
const navigationIntegration = Sentry.reactNavigationIntegration({
enableTimeToInitialDisplay: !isRunningInExpoGo(),
});
Sentry.init({
dsn: 'YOUR DSN HERE',
debug: true,
tracesSampleRate: 1.0,
integrations: [navigationIntegration],
enableNativeFramesTracking: !isRunningInExpoGo(),
});
function RootLayout() {
const ref = useNavigationContainerRef();
useEffect(() => {
if (ref?.current) {
navigationIntegration.registerNavigationContainer(ref);
}
}, [ref]);
return <Slot />;
}
export default Sentry.wrap(RootLayout);
Step 8: Test Your Setup
- Add a test button in one of your screens:
import { Button } from 'react-native';
<Button title="Press me" onPress={() => { throw new Error('Hello, Sentry!'); }} />
Conclusion: Effective error handling is vital for mobile apps. Integrating Sentry with your Expo React Native app not only helps in identifying and resolving issues swiftly but also improves user satisfaction by ensuring fewer bugs reach production.
Implement Sentry in your next project for a more robust error tracking system, and share your experiences in the comments!
Try BanKan Board — The Project Management App Made for Developers, by Developers
If you’re tired of complicated project management tools with story points, sprints, and endless processes, BanKan Board is here to simplify your workflow. Built with developers in mind, BanKan Board lets you manage your projects without the clutter.
Key Features:
- No complicated processes: Focus on what matters without the overhead of traditional project management systems.
- Claude AI Assistant: Get smart assistance to streamline your tasks and improve productivity.
- Free to Use: Start using it without any upfront cost.
- Premium Features: Upgrade to unlock advanced functionality tailored to your team’s needs.
Whether you’re building a side project, managing a team, or collaborating on open-source software, BanKan Board is designed to make your life easier. Try it today!