1- import type { Carrier } from '@sentry/core' ;
2- import { getHubFromCarrier , getMainCarrier , hasTracingEnabled } from '@sentry/core' ;
1+ import { hasTracingEnabled } from '@sentry/core' ;
32import { RewriteFrames } from '@sentry/integrations' ;
43import type { NodeOptions } from '@sentry/node' ;
54import { configureScope , getCurrentHub , init as nodeInit , Integrations } from '@sentry/node' ;
65import type { EventProcessor } from '@sentry/types' ;
76import type { IntegrationWithExclusionOption } from '@sentry/utils' ;
87import { addOrUpdateIntegration , escapeStringForRegex , logger } from '@sentry/utils' ;
9- import * as domainModule from 'domain' ;
108import * as path from 'path' ;
119
1210import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor' ;
@@ -55,8 +53,6 @@ const globalWithInjectedValues = global as typeof global & {
5553 __rewriteFramesDistDir__ : string ;
5654} ;
5755
58- const domain = domainModule as typeof domainModule & { active : ( domainModule . Domain & Carrier ) | null } ;
59-
6056// TODO (v8): Remove this
6157/**
6258 * @deprecated This constant will be removed in the next major update.
@@ -87,16 +83,6 @@ export function init(options: NodeOptions): void {
8783 // Right now we only capture frontend sessions for Next.js
8884 options . autoSessionTracking = false ;
8985
90- // In an ideal world, this init function would be called before any requests are handled. That way, every domain we
91- // use to wrap a request would inherit its scope and client from the global hub. In practice, however, handling the
92- // first request is what causes us to initialize the SDK, as the init code is injected into `_app` and all API route
93- // handlers, and those are only accessed in the course of handling a request. As a result, we're already in a domain
94- // when `init` is called. In order to compensate for this and mimic the ideal world scenario, we stash the active
95- // domain, run `init` as normal, and then restore the domain afterwards, copying over data from the main hub as if we
96- // really were inheriting.
97- const activeDomain = domain . active ;
98- domain . active = null ;
99-
10086 nodeInit ( options ) ;
10187
10288 const filterTransactions : EventProcessor = event => {
@@ -118,20 +104,6 @@ export function init(options: NodeOptions): void {
118104 }
119105 } ) ;
120106
121- if ( activeDomain ) {
122- const globalHub = getHubFromCarrier ( getMainCarrier ( ) ) ;
123- const domainHub = getHubFromCarrier ( activeDomain ) ;
124-
125- // apply the changes made by `nodeInit` to the domain's hub also
126- domainHub . bindClient ( globalHub . getClient ( ) ) ;
127- domainHub . getScope ( ) ?. update ( globalHub . getScope ( ) ) ;
128- // `scope.update()` doesn’t copy over event processors, so we have to add it manually
129- domainHub . getScope ( ) ?. addEventProcessor ( filterTransactions ) ;
130-
131- // restore the domain hub as the current one
132- domain . active = activeDomain ;
133- }
134-
135107 __DEBUG_BUILD__ && logger . log ( 'SDK successfully initialized' ) ;
136108}
137109
0 commit comments