sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

@sentry/nextjs: NEXT_PUBLIC_SENTRY_DSN is not used

Open AsherFoster opened this issue 5 years ago • 6 comments

  • [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,
  // ...
})

AsherFoster avatar May 19 '21 01:05 AsherFoster

Hi @AsherFoster, is NEXT_PUBLIC_SENTRY_DSN in your environment?

iker-barriocanal avatar May 19 '21 08:05 iker-barriocanal

@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 avatar May 20 '21 04:05 AsherFoster

@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 avatar May 20 '21 09:05 iker-barriocanal

@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 avatar May 21 '21 00:05 AsherFoster

@AsherFoster yes, converted the docs PR to draft since this will be supported. I'll keep this updated, and thanks for the feedback!

iker-barriocanal avatar May 21 '21 09:05 iker-barriocanal

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.

HazAT avatar May 28 '21 08:05 HazAT