React Native
Sentry's React Native SDK enables automatic reporting of errors and exceptions, and identifies performance issues in your application. The React Native SDK includes performance monitoring (our @sentry/tracing
package) by default.
Features:
- Automatic Native Crash Error Tracking (using both
sentry-cocoa
&sentry-android
) - Offline storage of events
- Events enriched with device data
- Autolinking
- Breadcrumbs created for outgoing
http
request with XHR and Fetch; UI and system events; and console logs - Release Health tracks crash free users and sessions
- Performance Monitoring creates transactions automatically for React Navigation v4 and above; creates spans automatically for XHR and Fetch
- Under the hood the SDK relies on our JavaScript SDK, which makes all functions available for JavaScript also available in this SDK
- On Device symbolication for JavaScript (in Debug)
- RAM bundle support
- Hermes support
- Expo support
On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application.
Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.
Install
Sentry captures data by using an SDK within your application’s runtime.
Add the @sentry/react-native
dependency:
npm install --save @sentry/react-native
Expo
If you are using Expo, see How to Add Sentry to Your Expo Project. This SDK works for both managed and bare projects.
Make sure that the version of @sentry/react-native
matches what sentry-expo
depends on, read more on our troubleshooting page.
Linking
If you are running a project with react-native
prior to 0.60, you still need to call react-native link
, otherwise you can skip this step as react-native
version 0.60 and above does this automatically.
Link the SDK to your native projects to enable native crash reporting.
react-native link @sentry/react-native
Execute the Sentry Wizard.
npx @sentry/wizard -i reactNative -p ios android
cd ios
pod install
The call to the Sentry Wizard will patch your project accordingly, though you can link manually if you prefer. You need to do this only once, then the created files can go into your version control system.
The following changes will be performed by Sentry Wizard:
- add the
sentry-android
package for native crash reporting on Android - add the
sentry-cocoa
package for native crash reporting on iOS - enable the Sentry Gradle build step for Android
- patch MainApplication.java for Android
- configure Sentry for the supplied DSN in your index.js/App.js files
- store build credentials in ios/sentry.properties and android/sentry.properties.
iOS Specifics
When you use Xcode, you can hook directly into the build process to upload debug symbols and source maps. However, if you are using bitcode, you will need to disable the “Upload Debug Symbols to Sentry” build phase and then separately upload debug symbols from iTunes Connect to Sentry.
Android Specifics
For Android, we hook into Gradle for the source map build process. When you run react-native link
, the Gradle files are automatically updated. When you run ./gradlew assembleRelease
or ./gradlew bundleRelease
, source maps are automatically built and uploaded to Sentry.
If you have enabled Gradle's org.gradle.configureondemand
feature, you'll need a clean build, or you'll need to disable this feature to upload the source map on every build.
To disable this feature, set org.gradle.configureondemand=false
or remove it as its default value is disabled, do this in the gradle.properties
file.
Configure
Configuration should happen as early as possible in your application's lifecycle.
Initialize
To initialize the SDK, you need to call:
App.js
import * as Sentry from "@sentry/react-native";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
});
Once this is done, all unhandled exceptions will be automatically captured by Sentry. You can also perform the following optional steps:
Wrap Your App
Wrap your app with Sentry to automatically instrument it with touch event tracking and automatic performance monitoring:
App.js
export default Sentry.wrap(App);
Enable Performance Monitoring
Learn how to enable Sentry's performance monitoring in your SDK to help you track your application performance, measuring metrics like throughput and latency.
Ensure Promise Rejection Handling is Active
Due to an issue with React Native's dependencies, unhandled promise rejections might not be correctly caught by Sentry. If the rejection handling is not active, our SDK might issue a warning:
WARN: Unhandled promise rejections might not be caught by Sentry. Read about how to fix this on our troubleshooting docs.
Visit our troubleshooting section to read on how to make sure promise rejection handling is active.
Verify
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
throw new Error("My first Sentry error!");
Or, try a native crash:
Sentry.nativeCrash();
Learn more about manually capturing an error or message in our Usage documentation.
To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
- Package:
- npm:@sentry/react-native
- Version:
- 5.27.0
- Repository:
- https://github.com/getsentry/sentry-react-native