1- import { getGlobalData , mergeScopeData } from '@sentry/core' ;
1+ import { getGlobalScope as _getGlobalScope , mergeScopeData , setGlobalScope } from '@sentry/core' ;
22import { OpenTelemetryScope } from '@sentry/opentelemetry' ;
33import type { Breadcrumb , Client , Event , EventHint , Severity , SeverityLevel } from '@sentry/types' ;
44import { uuid4 } from '@sentry/utils' ;
@@ -24,20 +24,17 @@ export function setCurrentScope(scope: Scope): void {
2424 * We overwrite this from the core implementation to make sure we get the correct Scope class.
2525 */
2626export function getGlobalScope ( ) : Scope {
27- const globalData = getGlobalData ( ) ;
28-
29- if ( ! globalData . globalScope ) {
30- globalData . globalScope = new Scope ( ) ;
31- }
27+ const globalScope = _getGlobalScope ( ) ;
3228
3329 // If we have a default Scope here by chance, make sure to "upgrade" it to our custom Scope
34- if ( ! ( globalData . globalScope instanceof Scope ) ) {
35- const oldScope = globalData . globalScope ;
36- globalData . globalScope = new Scope ( ) ;
37- globalData . globalScope . update ( oldScope ) ;
30+ if ( ! ( globalScope instanceof Scope ) ) {
31+ const newScope = new Scope ( ) ;
32+ newScope . update ( globalScope ) ;
33+ setGlobalScope ( newScope ) ;
34+ return newScope ;
3835 }
3936
40- return globalData . globalScope as Scope ;
37+ return globalScope ;
4138}
4239
4340/** Get the currently active isolation scope. */
@@ -97,6 +94,7 @@ export class Scope extends OpenTelemetryScope implements ScopeInterface {
9794 newScope . _attachments = [ ...this [ '_attachments' ] ] ;
9895 newScope . _sdkProcessingMetadata = { ...this [ '_sdkProcessingMetadata' ] } ;
9996 newScope . _propagationContext = { ...this [ '_propagationContext' ] } ;
97+ newScope . _client = this . _client ;
10098
10199 return newScope ;
102100 }
0 commit comments