Repository navigation
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/nextjs
SDK Version
7.34.0
Framework Version
@sentry/nextjs 7.34.0
Link to Sentry event
No response
SDK Setup
The sample repro repository uses the following values:
sentry.client.config.js:
Sentry.init({
...sentryConfigShared,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
});sentry.client.edge.js:
Sentry.init({
...sentryConfigShared,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
});sentry.client.server.js:
Sentry.init({
...sentryConfigShared,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
});Steps to Reproduce
We use environment variables (injected with dotenv) to setup the Sentry DSN/environment for our app's different environments (eg, staging and production). This has worked fine until @sentry/nextjs 7.34.0 where this workflow has broken. I believe this is a result of this #6927 (cc @lforst) which seems to put the sentry config before the app code? (and thus the Sentry initialisation is performed before Next calls setConfig here to populate the data from __NEXT_DATA__ – which contains our inlined environment variables)
I've created a sample app which reproduces the issue as described in the steps to reproduce below:
- Clone this repository, which is a reproduction of the issue
- run
yarn build && yarn start:production - Observe an error in the browser console
(optionally, revert to @sentry/nextjs 7.33.0 and observe the error does not occur.
Expected Result
No error occurs (like this screenshot when using 7.33.0):
Actual Result
Unable to access environment variables during Sentry client initialisation (like this screenshot when using 7.34.0):
We were wondering whether it was possible to revert this change so the sentry initialisation is done after Next populates its environment variables? Thanks!


Activity
lforst commentedon Feb 1, 2023
Hi, thanks for reporting this and doing the research! It helped a lot. We will change the injection location back to
_appwhich should fix this.josh- commentedon Feb 1, 2023
Great! Thanks so much for the super-fast turnaround @lforst 🎉
lforst commentedon Feb 1, 2023
Hi, we just released an update that should fix this problem. https://github.com/getsentry/sentry-javascript/releases/tag/7.35.0
Let me know if upgrading the SDK fixes this issue for you!
josh- commentedon Feb 1, 2023
Yep looking good for us - thanks so much 👍