-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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!

