Search code examples
reactjsreact-nativesentry

Where to initialize sentry.init in a react native app


In my react native application, to track errors I'm going to use sentry. So, where exactly should I use Sentry.init?

I tried to use this in app.ts, inside useEffect. But, if there are any error before loads the app, those errors are not tracked with this.

Where should I use this code to work sentry properly?

 Sentry.init({
    dsn: SENTRY_DSN,
    environment: ENVIRONMENT,
 });

Solution

  • In my projects I use like this and I got all errors (before App component)

    import * as Sentry from '@sentry/react-native';
    Sentry.init({
      dsn: 'https://71c4b3f6a9b646c992175aa6cc095c08@o312251.ingest.sentry.io/1781718'
    });
    
    
    export default class App extends Component {
    ...
    }