React Native

This is the documentation for our React Native SDK. The React Native SDK uses a native extension for iOS and Android but will fall back to a pure JavaScript version if necessary.

Getting Started

Getting started with Sentry is a three step process:

  1. Sign up for an account
  2. Install your SDK
  3. Configure it

Installation

Start by adding Sentry and then linking it:

Copied
npm install react-native-sentry --save
# or
# yarn add react-native-sentry
# if you are using yarn
# this is for linking
react-native link react-native-sentry

The link step will pull in the native dependency and patch your project accordingly. If you are using expo you don’t have to (or can’t) run that link step. For more information about that see Using Sentry with Expo.

On linking the new Sentry Wizard will help you to configure your project and change files accordingly.

Upon linking the following changes will be performed:

  • add the sentry-java 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 AppDelegate.m for iOS
  • 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.

To see what is happening during linking you can refer to Manual Setup which will give you all the details.

Note that we only support react-native >= 0.38 at the moment.

Upgrading

If you are upgrading from an earlier version of sentry-react-native you should re-link the package to ensure the generated code is updated to the latest version:

Copied
react-native unlink react-native-sentry
react-native link react-native-sentry

iOS Specifics

When you use Xcode you can hook directly into the build process to upload debug symbols and source maps. If you however 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 source maps are automatically built and uploaded to Sentry.

Client Configuration

When you run react-native link we will automatically update your index.ios.js / index.android.js with the following changes:

Copied
import { Sentry } from "react-native-sentry";
Sentry.config("https://examplePublicKey@o0.ingest.sentry.io/0").install();

You can pass additional configuration options to the config() method if you want to do so.

Mixed Stack Traces

Currently we only support mixed stack traces on iOS. By default this feature is disabled. We recommend testing your app thoroughly when activating this, to turn it on deactivateStacktraceMerging: false see: Additional Configuration.

Deep Dive