Expo
Learn how to set up an Expo-managed project with the Sentry React Native SDK.
To set up the Sentry React Native SDK in your Expo project, follow the steps on this page.
- Expo SDK 50 or newer.
- Expo SDK 49 and older are supported by the
sentry-expo
package.
- Expo SDK 49 and older are supported by the
- Migrate from
sentry-expo
to@sentry/react-native
. - Sign up for an account.
Use the Sentry Wizard to patch your project automatically, as shown below. Alternatively, you can follow the Manual Install if you prefer. You only need to patch the project once. Then, you can add the patched files to your version control system.
npx @sentry/wizard@latest -i reactNative
The following tasks will be performed by the Sentry Wizard
- Install the
@sentry/react-native
package. - Add the
@sentry/react-native/metro
to the metro.config.js Metro configuration. - Add the
@sentry/react-native/expo
to the app.json Expo configuration. - Enable the Sentry React Native Gradle build step for Android to auto-upload generated source maps and debug symbols.
- Wrap the Bundle React Native code and images Xcode project build phase script to upload generated source maps and collect bundled node modules.
- Add Upload Debug Symbols to Sentry Xcode project build phase.
- Run
pod install
. - Store build credentials in ios/sentry.properties, android/sentry.properties and env.local.
- Configure Sentry for the supplied DSN in your layout.tsx file.
If you don't use the Wizard, install the @sentry/react-native
package:
npx expo install @sentry/react-native
Import the @sentry/react-native
package and call init
with your DSN:
import { Text, View } from "react-native";
import * as Sentry from "@sentry/react-native";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
});
function App() {
return (
<View>
<Text>Expo Example!</Text>
</View>
);
}
export default Sentry.wrap(App);
Wrap the root component of your application with Sentry.wrap
:
export default Sentry.wrap(App);
To ensure bundles and source maps are automatically uploaded during the native applications builds, add withSentry
to the Expo application configuration:
{
"expo": {
"plugins": [
[
"@sentry/react-native/expo",
{
"url": "https://sentry.io/",
"note": "Use SENTRY_AUTH_TOKEN env to authenticate with Sentry.",
"project": "example-project",
"organization": "example-org"
}
]
]
}
}
Add auth token to your environment:
# DO NOT COMMIT YOUR AUTH TOKEN
export SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
To ensure unique Debug IDs get assigned to the generated bundles and source maps, add Sentry Serializer to the Metro configuration:
// 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 certain information about the device and the application for its essential functionality. Some of the APIs required for this are considered privacy-relevant. Add the privacy manifest to your Xcode project to ensure your app is compliant with Apple's guidelines. Read the Apple Privacy Manifest guide for more info on how to add records required for the Sentry SDKs.
To verify that everything is working as expected, build the Release
version of your application and send a test event to Sentry by adding:
<Button
title="Try!"
onPress={() => {
Sentry.captureException(new Error("First error"));
}}
/>;
- Learn how to upload source maps for native builds and Expo Updates
- Add automatic tracing with Expo Router
- Don't commit your auth token. Instead, use an environment variable like
SENTRY_AUTH_TOKEN
. - Source maps for the
Release
version 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.
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").