How to limit Sentry to only capture events when in production in NextJS? #8546
-
I'm moving from React to NextJS and I'm having issues limiting Sentry to only run on production environments. What I used to do was: if (process.env.NODE_ENV === 'production') {
Sentry.init({
dsn: process.env.REACT_APP_SENTRY_DSN,
tracesSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
environment: process.env.NODE_ENV,
release: `${process.env.REACT_APP_NAME}-${process.env.REACT_APP_VERSION}`,
integrations: [
new BrowserTracing(),
new Replay({
maskAllText: false,
blockAllMedia: false
})
]
});
} I have a new project that I'm writing in NextJS but the process for initializing Sentry is different. I used a wizard to help set everything up. Now I'm unclear as to where I would do my |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @dokgu, using What we recommend doing though is only setting |
Beta Was this translation helpful? Give feedback.
Hey @dokgu, using
process.env.NODE_ENV === 'production'
should work as well!What we recommend doing though is only setting
process.env.REACT_APP_SENTRY_DSN
in production, as passing a undefined DSN to theSentry.init
calls disables Sentry and it's functionality.