You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(nextjs): Always initialize SDK with global hub (#4086)
In a nextjs app using `@sentry/nextjs`, the code which initializes the SDK is kicked off by the first incoming request[1]. Because we use domains to prevent scope bleed between requests, at the time when `Sentry.init()` is called, we're already in a domain, and as a result, @sentry/node's `init` function sets the domain's hub as the global hub, the hub from which all subsequent hubs will inherit. This means that - currently - all future hubs inherit data from that first request, which they shouldn't.
This PR fixes that by essentially deactivating the domain while the SDK is initialized, so that all initialization code will act on the global hub. Then, because ideally the domain hub would have inherited from the global hub, the work done to the global hub is copied over to the domain hub (to mimic the effects of the inheritance) before the domain is made active again.
[1] It's the request handler's loading of either `_app` or the API route handler (both of which we've prefaced with the user's `sentry.server.config.js`) which triggers the user's `Sentry.init` to run.
0 commit comments