skip to Main Content

What is the recommended way to avoid sending debug errors 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);

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. If you just wanna minimise it you can below solution:

    Sentry.init({
      debug: false // or use env like !isDev || !isStg
    })
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search