-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(nextjs): Disable server instrumentation on Vercel #4255
fix(nextjs): Disable server instrumentation on Vercel #4255
Conversation
size-limit report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest renaming the PR to "Disable server instrumentation on Next 12", which seems to be closer to the intent.
I'm missing what of this current patch makes it specific to Next 12 vs disabling the instrumentation for any version.
(And missing tests)
// or | ||
// `node /var/runtime/index.js`. | ||
const isBuild = new RegExp('build').test(process.argv.toString()); | ||
const isVercel = !!process.env.VERCEL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we look for VERCEL=1
specifically? !!process.env.VERCEL
means isVercel
is true as long as the environment variable is defined (even for values that would be surprising to consider true, such as VERCEL=0
, VERCEL=no
and VERCEL=false
).
https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ignore this for now as it's been like this for sometime already and we can address it later.
// `node next start` | ||
// or | ||
// `node /var/runtime/index.js`. | ||
const isBuild = new RegExp('build').test(process.argv.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern is a fixed string, there's no need to use a RegExp -- we could use String.indexOf
or String.includes
.
Also, process.argv.toString()
seems brittle -- this could produce the incorrect output if "build" appears somewhere on the path / args by chance.
const isBuild = new RegExp('build').test(process.argv.toString()); | |
const isBuild = process.argv.toString().indexOf('build') >= 0; |
I could give a better suggestion once I understand what exactly was the intent here (are we trying to cover the first and second cases of the comment?).
The condition to check whether the `vercel` tag is added to vercel is resolved in `index.server.ts` at the module level. The `VERCEL` env var should be set (or not) when the module is imported, instead of importing it and then initing the app.
Nothing, it disables server instrumentation on every version. It's relevant to Next 12 because it's the first version that crashes with that instrumentation. |
}); | ||
// TODO: test `vercel` tag when running on Vercel | ||
// Can't just add the test and set env variables, since the value in `index.server.ts` | ||
// is resolved when importing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can patch the value of isVercel
(doesn't have to be now)
…om:getsentry/sentry-javascript into kmclb-nextjs-no-instrumentserver-on-vercel
On Vercel, the server instrumentation has no effect. Errors and transactions are captured through the [custom `_error.js` page](https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#create-a-custom-_error-page) and the [`withSentry` handler](https://docs.sentry.io/platforms/javascript/guides/nextjs/#configure). Not instrumenting the server (to not import any modules from `next`) when an app is deployed on Vercel should fix the issue.
This work has been done by @lobsterkatie.
Resolves #4207 and #4103.
On Vercel, the server instrumentation has no effect. Errors and transactions are captured through the custom
_error.js
page and thewithSentry
handler. Not instrumenting the server (to not import any modules fromnext
) when an app is deployed on Vercel should fix the issue.