react-nativesentryreact-native-sentry

How to prevent Sentry from sending events in development mode in React Native?


What is the recommended way to avoid sending errors generated while developing to Sentry in JS and the native side?

JS error in Dev mode

Native crash error in Dev mode

What was tried for Sentry @sentry/react-native version 6.1.0, but it did not work:

Option 1:

Sentry.init({
  enabled: !__DEV__
  dsn: "SOME_VALID_URL"
})

Result: This just works for js errors, but keep sending native errors to Sentry

Option 2:

if(!__DEV__) {
  Sentry.init({
    dsn: "SOME_VALID_URL"
  })
}

Result: This will generate a warning when using Sentry.wrap in the root component

App Start Span could not be finished. Sentry.wrap was called before Sentry.init.

if(!__DEV__) {
  Sentry.init({
    dsn: "SOME_VALID_URL"
  })
}

function RootLayout() {
 ...
}

export default Sentry.wrap(RootLayout);

Solution

  • According to the Sentry options docs, it suggests setting dns to undefined.

    • The Dsn used to connect to Sentry and identify the project. If omitted, the SDK will not send any data to Sentry.
    Sentry.init({
      dsn: __DEV__
        ? undefined
        : "YOUR_SENTRY_DSN_URL"
    })
    

    Be careful with enabled: !__DEV__. It currently keeps sending native errors generated in dev mode

    Source:

    How to disable sentry in development ?

    How to disable sentry while debugging?

    Enabled option in Sentry init does not avoid sending native events to Sentry in Dev mode