Native Initialization

Learn how to manually initialize the native SDKs.

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. You can initialize the native SDKs yourself to overcome this limitation or if you want to provide custom options above what the React Native SDK currently provides.

To do this, set autoInitializeNativeSdk to false in the init options:

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  autoInitializeNativeSdk: false,
});

This will prevent the React Native SDK from initializing the native SDK automatically.

Next, initialize the native SDKs for Android, which is documented below, or for iOS by following the configuration guide to initialize the Sentry Cocoa SDK. Note that you do not need to install the native SDKs as they are already packaged with the React Native SDK.

When you initialize the native SDKs yourself with autoInitializeNativeSdk: false, the JavaScript and native layers are configured independently. Keep the following in mind:

  • Sentry.init() is still required in JavaScript. The native SDK only captures native errors and crashes (with native stack traces). To capture JavaScript errors and use APIs like Sentry.captureException(), you must still call Sentry.init() on the JS layer.
  • The dsn is required on both sides. Set it in both the native initialization and Sentry.init(). You can point each layer at a different project (for example, separate projects for JavaScript, iOS, and Android), but we recommend using a single project unless you specifically need them separated.
  • Options are not merged. With autoInitializeNativeSdk: false, the options you pass to Sentry.init() are not forwarded to the native SDKs. Each layer uses only the options it was initialized with, so any option you want applied natively must be set in the native initialization.
  • Avoid enabling tracing on both layers. If you enable performance tracing (for example, tracesSampleRate together with enableAutoPerformanceTracing) in both the native and JS layers, screen navigation and other instrumentation are captured independently by each layer, resulting in duplicate transactions in Sentry. When the native SDK is initialized automatically from JS (autoInitializeNativeSdk: true), the React Native SDK avoids this by not forwarding tracesSampleRate to the native layer.

To enable App Start Instrumentation and Slow and Frozen Frames on iOS when initializing the Sentry Cocoa SDK manually, you have to configure the sample rate.

To use auto-init, add the following to your AndroidManifest.xml:

Copied
<meta-data
  android:name="io.sentry.auto-init"
  tools:replace="android:value"
  android:value="true"
/>

Then follow the guide on initializing Android.

If you want to manually initialize the Android SDK without using the content provider, you can then follow the manual initialization guide without needing to add the tag since io.sentry.auto-init is set to false by the React Native SDK.

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").