@sentry/nextjs: NEXT_PUBLIC_SENTRY_DSN is not used
- [x] Review the documentation: https://docs.sentry.io/
- [x] Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- [x] Use the latest release: https://github.com/getsentry/sentry-javascript/releases
- [ ] Provide a link to the affected event from your Sentry account
Package + Version
@sentry/nextjs@ 6.4.0@sentry/tracing@ 6.4.0
Description
According to a note at the end of the manual setup guide, you can use either the SENTRY_DSN or NEXT_PUBLIC_SENTRY_DSN environment variable to set Sentry's DSN.
Setting NEXT_PUBLIC_SENTRY_DSN (such as through the official Sentry/Vercel integration) doesn't configure the DSN. It appears that NEXT_PUBLIC_SENTRY_DSN isn't referenced at all in the code, and SENTRY_DSN only appears to be supported by @sentry/node, leaving the client-side unconfigured.
Ideally, @sentry/nextjs would be updated to utilise these variables, or the documentation updated to remove this information.
Our current solution is to explicitly specify the DSN in sentry.client.config.js and sentry.server.config.js:
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// ...
})
Hi @AsherFoster, is NEXT_PUBLIC_SENTRY_DSN in your environment?
@iker-barriocanal, yup, we have it configured in Vercel's environment variables. I've also double checked using next build locally, using both NEXT_PUBLIC_SENTRY_DSN and SENTRY_DSN variables, and neither results in the client DSN being set.
@AsherFoster you can use both NEXT_PUBLIC_SENTRY_DSN and SENTRY_DSN, but you still need to set the DSN in the SDK.
@iker-barriocanal thanks for the clarification and working on updating the docs!
In hindsight, I can definitely see how I misinterpreted the docs. Additionally, the @sentry/node appearing to support setting the DSN by environment variable threw me off. I think it'd be beneficial to support using environment variables, but that's only my personal opinion.
@AsherFoster yes, converted the docs PR to draft since this will be supported. I'll keep this updated, and thanks for the feedback!
We use the NEXT_PUBLIC_SENTRY_DSN in the config file we create with the wizard see: https://github.com/getsentry/sentry-wizard/blob/master/scripts/NextJs/configs/sentry.client.config.js
so we pick it up and use it if it's there.