Expo
Experimental Support
Expo support is currently experimental and available since Sentry React Native SDK version 5.16.0-alpha.4
and Expo SDK version 50.
Experimental support means it may have bugs. We recognize the irony.
To set up the Sentry React Native SDK in your Expo project, follow the steps on this page.
Prerequisities
- 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.
Install the Sentry SDK
Install the @sentry/react-native
package:
npx expo install @sentry/react-native
Intialize the SDK
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 performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
});
function App() {
return (
<View>
<Text>Expo Example!</Text>
</View>
);
}
export default Sentry.wrap(App);
Wrap Your App
Wrap the root component of your application with Sentry.wrap
:
export default Sentry.wrap(App);
Add the Sentry Expo Plugin
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/",
"warning": "DO NOT COMMIT YOUR AUTH TOKEN",
"authToken": "sntrys_YOUR_TOKEN_HERE",
"project": "example-project",
"organization": "example-org"
}
]
]
}
}
Add Sentry Metro Plugin
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;
Verify Setup
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"));
}}
/>
Next Steps
Notes
- 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").
- Package:
- npm:@sentry/react-native
- Version:
- 5.18.0
- Repository:
- https://github.com/getsentry/sentry-react-native