Skip to content

@sentry/nextjs v7.34.0 breaks environment variable initialisation workflow #7006

@josh-

Description

@josh-

Is there an existing issue for this?

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:

  1. Clone this repository, which is a reproduction of the issue
  2. run yarn build && yarn start:production
  3. 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):

image

Actual Result

Unable to access environment variables during Sentry client initialisation (like this screenshot when using 7.34.0):

image

We were wondering whether it was possible to revert this change so the sentry initialisation is done after Next populates its environment variables? Thanks!

Metadata

Metadata

Assignees

Labels

Package: nextjsIssues related to the Sentry Nextjs SDK

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions