1
- import { getGlobalData , mergeScopeData } from '@sentry/core' ;
1
+ import { getGlobalScope as _getGlobalScope , mergeScopeData , setGlobalScope } from '@sentry/core' ;
2
2
import { OpenTelemetryScope } from '@sentry/opentelemetry' ;
3
3
import type { Breadcrumb , Client , Event , EventHint , Severity , SeverityLevel } from '@sentry/types' ;
4
4
import { uuid4 } from '@sentry/utils' ;
@@ -24,20 +24,17 @@ export function setCurrentScope(scope: Scope): void {
24
24
* We overwrite this from the core implementation to make sure we get the correct Scope class.
25
25
*/
26
26
export function getGlobalScope ( ) : Scope {
27
- const globalData = getGlobalData ( ) ;
28
-
29
- if ( ! globalData . globalScope ) {
30
- globalData . globalScope = new Scope ( ) ;
31
- }
27
+ const globalScope = _getGlobalScope ( ) ;
32
28
33
29
// 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 ;
38
35
}
39
36
40
- return globalData . globalScope as Scope ;
37
+ return globalScope ;
41
38
}
42
39
43
40
/** Get the currently active isolation scope. */
@@ -97,6 +94,7 @@ export class Scope extends OpenTelemetryScope implements ScopeInterface {
97
94
newScope . _attachments = [ ...this [ '_attachments' ] ] ;
98
95
newScope . _sdkProcessingMetadata = { ...this [ '_sdkProcessingMetadata' ] } ;
99
96
newScope . _propagationContext = { ...this [ '_propagationContext' ] } ;
97
+ newScope . _client = this . _client ;
100
98
101
99
return newScope ;
102
100
}
0 commit comments