React Native Navigation

Learn how to use Sentry's React Native Navigation instrumentation.

Sentry's React Native SDK package ships with instrumentation for React Native Navigation. This allows you to see the performance of your navigation transitions and the errors that occur during them. This page will guide you through setting up the instrumentation and configuring it to your needs.

You will need to pass the Navigation object imported from the library to initialize our routing instrumentation. It is recommended that you initialize our SDK and the routing instrumentation as early as possible in the lifecycle of your app; this would most likely be before the point where you initialize your screens.

index.js
Copied
import * as Sentry from "@sentry/react-native";
import { Navigation } from "react-native-navigation";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [
    Sentry.reactNativeNavigationIntegration({
      navigation: Navigation,
    }),
  ],
});

You can configure the instrumentation by passing an options object to the constructor:

Copied
Sentry.reactNativeNavigationIntegration({
  navigation: Navigation, // Navigation from `react-native-navigation`
  routeChangeTimeoutMs: 1_000, // default: 1_000
  enableTabsInstrumentation: true, // default: false
  ignoreEmptyBackNavigationTransactions: true, // default: true
});

This option is required and should be the Navigation object imported from the navigation library.

This option specifies how long the instrumentation will wait for the route to mount after a change has been initiated before the transaction is discarded. The default value is 1_000.

This instrumentation will create a transaction on tab change. By default, only navigation commands create transactions. The default value is false.

This ensures that transactions that are from routes that've been seen and don't have any spans, are not being sampled. This removes a lot of clutter, making it so that most back navigation transactions are now ignored. The default value is true.

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