-
-
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
feat(nextjs): Remove client.(server|client).config.ts
functionality in favor of instrumentation.ts
#11059
Conversation
…udge towards using `instrumentation.ts`
How does edge/client/server specific config work with |
You do // instrumentation.ts
import * as Sentry from '@sentry/nextjs';
export function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
Sentry.init({
dsn: '...',
});
} else if (process.env.NEXT_RUNTIME === 'edge') {
Sentry.init({
dsn: '...',
});
}
} And the multiplexer™ handles the rest 😎 |
client.(server|client).config.ts
and nudge towards using instrumentation.ts
client.(server|client).config.ts
functionality in favor of instrumentation.ts
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.
Nice! I agree, being more Framework-native is a good change. Can we also update the package README? I think this is safe to update the readme now and docs when we go stable. Also reminder for us to adjust the wizard for v8.
MIGRATION.md
Outdated
#### Updated the recommended way of calling `Sentry.init()` | ||
|
||
With version 8 of the SDK we will no longer support the use of `sentry.server.config.ts` and `sentry.edge.config.ts` | ||
files (note that `sentry.client.config.ts` is still supported and encouraged). Instead, please initialize the Sentry |
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.
l: I think the note about the client config should be its own sentence and maybe bold. Users might skip over the sentence and think everything is now initialized in instrument.ts
.
import * as Sentry from '@sentry/nextjs'; | ||
|
||
export function register() { | ||
if (process.env.NEXT_RUNTIME === 'nodejs' || process.env.NEXT_RUNTIME === 'edge') { |
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.
This begs a question: Suppose I have the same config for node and edge (as in this example). Do I even need the if
statement? Asking because I guess this is a common thing for users and if it's indeed necessary, we should point that out.
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.
This is more to be in line with what the Next.js docs say and to be forwards compatible. Let's say Next.js also starts running the register hook on the browser, not having the if statement would horribly fail in some cases.
… in favor of `instrumentation.ts` (getsentry#11059)
Ref #11042
Ref #11046
Because Next.js OTEL implementations require tracers to be set up in
instrumentation.ts
(not doing so breaks parent-child relationships between spans for some reason) we need to change how users configure the SDK.With this change we will not pick up
client.(server|client).config.(ts|js)
files any longer and instead require users to initialize the serverside SDKs insideinstrumentation.ts
. Because users may miss this critical step, we log a message if we detect the presence of the old config files.An added benefit of this PR is that it moves us a tiny step closer to not depending on webpack build-time magic for whenever turbopack ships. I personally find it cool that we are moving into a more "native" way of setting up monitoring for Next.js with this PR.
This PR also adjusts the typing for
withSentryConfig
to be more in line with what it actually does (i.e. we now accept basically any input and just return the same type).