sentry-javascript: [react] Sentry.captureException only works if in same file as Sentry.init

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

7.50.0

Framework Version

17.0.2

Link to Sentry event

No response

SDK Setup

Sentry.init({
  dsn: 'MY_DSN',
  debug: true,
  autoSessionTracking: true,
  normalizeDepth: 5,
  tracesSampleRate: 1.0,
  enabled: true,
  environment: 'development',
  beforeSend(event, hint) {
    console.log('beforeSend', { event, hint });

    return event;
  }
});

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
);

Steps to Reproduce

  1. init Sentry in index.tsx (root where react render is called)
  2. try using Sentry.captureException anywhere else in the application

Expected Result

Sentry.captureException sends an exception event to sentry

Actual Result

nothing is sent. nothing in network tab, nothing in beforeSend hook

the only time anything is sent is if i use Sentry.captureException in the index.tsx directly below the Sentry.init setup.

i have tried with debug and using beforeSend but the only one that shows up is the one in index.tsx.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 25 (9 by maintainers)

Most upvoted comments

@ci-vamp in development mode React maybe capturing the error globally. Could you try running in production mode?

i will try to create a reproduction but the only way i can think of is to cut out all of the code in our codebase but leave the config (webpack etc) the same so its reproducible. cant share all the project code as it is because its closed source