Sentry for Expo
Learn how to set up Sentry in an Expo project and capture your first events, including Expo config plugin, Expo Router tracing, Expo Updates context, and EAS dashboard integration.
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up the Sentry Expo SDK.Use this guide to set up Sentry's React Native SDK in an Expo project. The same @sentry/react-native SDK powers bare React Native and Expo apps. This guide covers Expo-specific setup, including the config plugin, Metro, and EAS.
If you don't already have an account and Sentry project, head over to sentry.io, then return to this page.
You need Expo SDK 50 or newer. The @sentry/react-native SDK requires Expo SDK 50+. On Expo SDK 49 or older, the deprecated sentry-expo package was used; migrate to @sentry/react-native to keep receiving updates.
Use the Sentry Wizard to patch your project automatically:
npx @sentry/wizard@latest -i reactNative
npx @sentry/wizard@latest -i reactNative
You only need to patch the project once. Add the patched files to version control. If you prefer, use the manual install below.
If you don't use the Wizard, install @sentry/react-native:
npx expo install @sentry/react-native
npx expo install @sentry/react-native
npm install @sentry/react-native --save
yarn add @sentry/react-native
pnpm add @sentry/react-native
Error Monitoring starts working as soon as you call Sentry.init(). Logs need enableLogs: true in the initialization snippet below, and you'll learn how to send them in Send Logs. Application Metrics need no extra configuration, and you'll learn how to send them in Send Application Metrics.
This guide also enables Tracing, Profiling, Session Replay, and User Feedback.
Import @sentry/react-native and initialize the SDK in your Expo Router root layout or app entry point.
The snippet also turns on:
- Tracing: via
tracesSampleRate - Profiling: via
profilesSampleRate(see Profiling) - Session Replay: via
mobileReplayIntegration()and the replay sample rates (see Session Replay) - User Feedback: via
feedbackIntegration()(see User Feedback) - Logs: via
enableLogs
Don't need a feature? Remove its integration and options from the snippet.
import * as Sentry from "@sentry/react-native";
Sentry.init({
dsn: "___PUBLIC_DSN___",
// Adds context data to events, such as IP address, cookies, and user.
sendDefaultPii: true,
integrations: [
// Enables Session Replay
Sentry.mobileReplayIntegration(),
// Enables User Feedback. Open the form with Sentry.showFeedbackWidget().
Sentry.feedbackIntegration(),
],
// Enables Tracing.
// Set to 1.0 to capture 100% of spans for tracing.
// We recommend reducing this value in production.
tracesSampleRate: 1.0,
// Enables Profiling for 100% of sampled transactions.
profilesSampleRate: 1.0,
// Enables Logs to be sent to Sentry.
enableLogs: true,
// Capture replays for 10% of sessions and 100% of sessions with an error.
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});
import * as Sentry from "@sentry/react-native";
Sentry.init({
dsn: "___PUBLIC_DSN___",
// Adds context data to events, such as IP address, cookies, and user.
sendDefaultPii: true,
integrations: [
// Enables Session Replay
Sentry.mobileReplayIntegration(),
// Enables User Feedback. Open the form with Sentry.showFeedbackWidget().
Sentry.feedbackIntegration(),
],
// Enables Tracing.
// Set to 1.0 to capture 100% of spans for tracing.
// We recommend reducing this value in production.
tracesSampleRate: 1.0,
// Enables Profiling for 100% of sampled transactions.
profilesSampleRate: 1.0,
// Enables Logs to be sent to Sentry.
enableLogs: true,
// Capture replays for 10% of sessions and 100% of sessions with an error.
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});
Wrap the root component of your application with Sentry.wrap:
import { Stack } from "expo-router";
import * as Sentry from "@sentry/react-native";
function RootLayout() {
return <Stack />;
}
export default Sentry.wrap(RootLayout);
import { Stack } from "expo-router";
import * as Sentry from "@sentry/react-native";
function RootLayout() {
return <Stack />;
}
export default Sentry.wrap(RootLayout);
To upload bundles and source maps automatically during native builds, add the Sentry plugin to your Expo app configuration. Add it to the plugins array in app.json, or wrap your config with withSentry in app.config.js or app.config.ts:
{
"expo": {
"plugins": [
[
"@sentry/react-native/expo",
{
"url": "https://sentry.io/",
"note": "Use SENTRY_AUTH_TOKEN env to authenticate with Sentry.",
"project": "___PROJECT_SLUG___",
"organization": "___ORG_SLUG___"
}
]
]
}
}
{
"expo": {
"plugins": [
[
"@sentry/react-native/expo",
{
"url": "https://sentry.io/",
"note": "Use SENTRY_AUTH_TOKEN env to authenticate with Sentry.",
"project": "___PROJECT_SLUG___",
"organization": "___ORG_SLUG___"
}
]
]
}
}
const { withSentry } = require("@sentry/react-native/expo");
const config = {
name: "Expo Example",
slug: "expo-example",
};
module.exports = withSentry(config, {
url: "https://sentry.io/",
// Use SENTRY_AUTH_TOKEN env to authenticate with Sentry.
project: "___PROJECT_SLUG___",
organization: "___ORG_SLUG___",
});
import { ExpoConfig } from "expo/config";
import { withSentry } from "@sentry/react-native/expo";
const config: ExpoConfig = {
name: "Expo Example",
slug: "expo-example",
};
export default withSentry(config, {
url: "https://sentry.io/",
// Use SENTRY_AUTH_TOKEN env to authenticate with Sentry.
project: "___PROJECT_SLUG___",
organization: "___ORG_SLUG___",
});
npx expo install adds the bare @sentry/react-native to the plugins array. Both @sentry/react-native and @sentry/react-native/expo are valid plugin paths. Expo resolves them the same way.
Add your auth token to a .env.local file in the root of your project:
.env.local# DO NOT COMMIT YOUR AUTH TOKEN
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
# DO NOT COMMIT YOUR AUTH TOKEN
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
Do not commit your auth token. Add .env.local to your .gitignore. For EAS builds, add SENTRY_AUTH_TOKEN as an EAS secret instead of using a .env.local file.
Add Sentry Serializer to the Metro configuration to assign unique Debug IDs to generated bundles and source maps:
// const { getDefaultConfig } = require("expo/metro-config");
const { getSentryExpoConfig } = require("@sentry/react-native/metro");
// const config = getDefaultConfig(__dirname);
const config = getSentryExpoConfig(__dirname);
module.exports = config;
// const { getDefaultConfig } = require("expo/metro-config");
const { getSentryExpoConfig } = require("@sentry/react-native/metro");
// const config = getDefaultConfig(__dirname);
const config = getSentryExpoConfig(__dirname);
module.exports = config;
The SDK needs access to some device and application information for essential functionality. Add the privacy manifest to your Xcode project to meet Apple's guidelines. See the Apple Privacy Manifest guide for the records required by the Sentry SDKs.
Connect Sentry to Expo Application Services (EAS) to view crash reports and Session Replays for deployments in the EAS dashboard, with direct links to Sentry stack traces and debugging context.
If you change your organization slug, update the configuration for this integration. See the troubleshooting guide.
You need Sentry owner, manager, or admin permissions to install this integration.
- Log in to your Expo dashboard and open Account Settings > Overview (
https://expo.dev/accounts/[your-account]/settings). - Find Connections and click Connect next to Sentry.
- Log in to Sentry and accept the integration into your organization. Expo will redirect you to Account Settings > Overview.
After connecting your accounts, link your Expo project to your Sentry project:
- Open Projects > [Your Project] > Configuration > Project settings in the Expo dashboard.
- Click Link and select your Sentry project.
To see Sentry issues and replays in the Expo dashboard, create an EAS Update channel and assign builds to it to create an EAS deployment. Then open Projects > [Your Project] > Updates > Deployments > [Deployment].
- Expo Updates — Automatic OTA update context, searchable tags, performance spans for update checks and downloads, and emergency launch alerts
- EAS Build Hooks — Capture build failures and lifecycle events from EAS Build
- Sentry Android Gradle Plugin — Advanced Android build configuration
- Expo Router tracing — Navigation transitions, performance spans, prefetch instrumentation, and per-route
ErrorBoundarycapture - Expo Image and Asset tracing — Automatic spans for
expo-imageandexpo-asset - Upload source maps for native builds and Expo Updates
- Don't commit your auth token. Store it in
.env.localasSENTRY_AUTH_TOKENfor local builds, and as an EAS secret for EAS builds. - Source maps for the
Releaseversion of your application are uploaded automatically during the native application build. - During development, the source code is resolved using the Metro Server and source maps aren't used. This currently doesn't work on web.
Use Sentry.logger to send logs at different levels. You can include attributes to search or filter by later.
The SDK can capture console.* calls when Logs are enabled. See the Console logging integration for details.
Sentry.logger.info("Order processed", { order_id: "order-123" });
Sentry.logger.warn("Slow operation detected", {
operation: "data_fetch",
duration_ms: 3500,
});
Sentry.logger.info("Order processed", { order_id: "order-123" });
Sentry.logger.warn("Slow operation detected", {
operation: "data_fetch",
duration_ms: 3500,
});
See Set Up Logs for all available logging methods and message formatting options.
Application Metrics are supported in React Native SDK 7.8.0 and newer. No extra option is needed after SDK initialization. Use Sentry.metrics to send counters, gauges, and distributions:
Sentry.metrics.count("checkout.failed", 1);
Sentry.metrics.gauge("active_connections", 42);
Sentry.metrics.distribution("api_latency", 187, { unit: "millisecond" });
Sentry.metrics.count("checkout.failed", 1);
Sentry.metrics.gauge("active_connections", 42);
Sentry.metrics.distribution("api_latency", 187, { unit: "millisecond" });
See Set Up Metrics for all available metric types and configuration options.
Build the Release version of your application, then capture a test error:
Sentry.captureException(new Error("First error"));
Sentry.captureException(new Error("First error"));
Open your project on Sentry.io to view the captured error.
At this point, you should have integrated Sentry into your Expo application. Here's what to explore next:
- Explore practical guides on what to monitor, log, track, and investigate after setup
- Configure Expo Router tracing
- Capture Expo Updates context
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").