Capture App Start Errors

Learn how to capture app start errors and crashes that occur before JavaScript loads using native initialization.

By default, the React Native SDK initializes the native SDK underneath the init method called on the JS layer. As a result, the SDK has a current limitation of not capturing native crashes that occur prior to the init method being called on the JS layer.

Starting with SDK version 8.0.0, you can initialize Sentry natively before JavaScript loads, enabling capture of app start errors and crashes that occur during:

  • Native module initialization
  • JavaScript bundle loading
  • Early React Native bridge setup

This feature uses a sentry.options.json configuration file and native initialization APIs that read from this file.

Create a sentry.options.json file in your React Native project root with the same options you currently have in Sentry.init:

sentry.options.json
Copied
{
  "dsn": "https://key@example.io/value",
  "debug": true,
  "environment": "production",
  "tracesSampleRate": 1.0,
  "enableTracing": true
}

Initialize Sentry in your MainApplication class:

Copied
import io.sentry.react.RNSentrySDK

class MainApplication : Application(), ReactApplication {
    override fun onCreate() {
        super.onCreate()
        RNSentrySDK.init(this)
        // ... rest of your initialization code
    }
}

Initialize Sentry in your AppDelegate before starting React Native so app start crashes are captured.

Copied
#import <RNSentry/RNSentry.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [RNSentrySDK start];
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

If you're using Expo, you can enable native initialization using the Expo plugin. First, create a sentry.options.json file in your project root (same location as your app.json) as above.

Add the useNativeInit option to your Expo plugin configuration:

app.json
Copied
{
  "expo": {
    "plugins": [
      [
        "@sentry/react-native/expo",
        {
          "useNativeInit": true
        }
      ]
    ]
  }
}

If you need to use environment variables or dynamic configuration, you can use app.config.js with the withSentry() wrapper instead of the array form in app.json:

app.config.js
Copied
import { withSentry } from "@sentry/react-native/expo";

export default withSentry(config, {
  useNativeInit: true,
});

When useNativeInit is set to true, the Expo plugin automatically:

  • Adds RNSentrySDK.init() to your Android MainApplication
  • Adds RNSentrySDK.start() to your iOS AppDelegate
Was this helpful?
Help improve this content
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").