1- import { getGlobalScope as _getGlobalScope , setGlobalScope } from '@sentry/core' ;
2- import { OpenTelemetryScope } from '@sentry/opentelemetry' ;
3- import type { Client , Event , EventHint , SeverityLevel } from '@sentry/types' ;
4- import { uuid4 } from '@sentry/utils' ;
1+ import { Scope as ScopeClass , getGlobalScope } from '@sentry/core' ;
2+ import type { Client } from '@sentry/types' ;
3+ import type { Scope } from '@sentry/types' ;
54
65import { getGlobalCarrier } from './globals' ;
7- import type { CurrentScopes , Scope as ScopeInterface , ScopeData , SentryCarrier } from './types' ;
6+ import type { CurrentScopes , SentryCarrier } from './types' ;
87
98/** Get the current scope. */
109export function getCurrentScope ( ) : Scope {
@@ -19,24 +18,6 @@ export function setCurrentScope(scope: Scope): void {
1918 getScopes ( ) . scope = scope ;
2019}
2120
22- /**
23- * Get the global scope.
24- * We overwrite this from the core implementation to make sure we get the correct Scope class.
25- */
26- export function getGlobalScope ( ) : Scope {
27- const globalScope = _getGlobalScope ( ) ;
28-
29- // If we have a default Scope here by chance, make sure to "upgrade" it to our custom Scope
30- if ( ! ( globalScope instanceof Scope ) ) {
31- const newScope = new Scope ( ) ;
32- newScope . update ( globalScope ) ;
33- setGlobalScope ( newScope ) ;
34- return newScope ;
35- }
36-
37- return globalScope ;
38- }
39-
4021/** Get the currently active isolation scope. */
4122export function getIsolationScope ( ) : Scope {
4223 return getScopes ( ) . isolationScope as Scope ;
@@ -70,103 +51,6 @@ export function isInitialized(): boolean {
7051 return ! ! getClient ( ) . getDsn ( ) ;
7152}
7253
73- /** A fork of the classic scope with some otel specific stuff. */
74- export class Scope extends OpenTelemetryScope implements ScopeInterface {
75- protected _client : Client | undefined ;
76-
77- /**
78- * @inheritDoc
79- */
80- public clone ( ) : Scope {
81- const newScope = new Scope ( ) ;
82- newScope . _breadcrumbs = [ ...this [ '_breadcrumbs' ] ] ;
83- newScope . _tags = { ...this [ '_tags' ] } ;
84- newScope . _extra = { ...this [ '_extra' ] } ;
85- newScope . _contexts = { ...this [ '_contexts' ] } ;
86- newScope . _user = { ...this [ '_user' ] } ;
87- newScope . _level = this [ '_level' ] ;
88- newScope . _span = this [ '_span' ] ;
89- newScope . _session = this [ '_session' ] ;
90- newScope . _transactionName = this [ '_transactionName' ] ;
91- newScope . _fingerprint = this [ '_fingerprint' ] ;
92- newScope . _eventProcessors = [ ...this [ '_eventProcessors' ] ] ;
93- newScope . _requestSession = this [ '_requestSession' ] ;
94- newScope . _attachments = [ ...this [ '_attachments' ] ] ;
95- newScope . _sdkProcessingMetadata = { ...this [ '_sdkProcessingMetadata' ] } ;
96- newScope . _propagationContext = { ...this [ '_propagationContext' ] } ;
97- newScope . _client = this . _client ;
98-
99- return newScope ;
100- }
101-
102- /** Update the client on the scope. */
103- public setClient ( client : Client ) : void {
104- this . _client = client ;
105- }
106-
107- /**
108- * Get the client assigned to this scope.
109- * Should generally not be used by users - use top-level `Sentry.getClient()` instead!
110- * @internal
111- */
112- public getClient ( ) : Client | undefined {
113- return this . _client ;
114- }
115-
116- /** Capture an exception for this scope. */
117- public captureException ( exception : unknown , hint ?: EventHint ) : string {
118- const eventId = hint && hint . event_id ? hint . event_id : uuid4 ( ) ;
119- const syntheticException = new Error ( 'Sentry syntheticException' ) ;
120-
121- getClient ( ) . captureException (
122- exception ,
123- {
124- originalException : exception ,
125- syntheticException,
126- ...hint ,
127- event_id : eventId ,
128- } ,
129- this ,
130- ) ;
131-
132- return eventId ;
133- }
134-
135- /** Capture a message for this scope. */
136- public captureMessage ( message : string , level ?: SeverityLevel , hint ?: EventHint ) : string {
137- const eventId = hint && hint . event_id ? hint . event_id : uuid4 ( ) ;
138- const syntheticException = new Error ( message ) ;
139-
140- getClient ( ) . captureMessage (
141- message ,
142- level ,
143- {
144- originalException : message ,
145- syntheticException,
146- ...hint ,
147- event_id : eventId ,
148- } ,
149- this ,
150- ) ;
151-
152- return eventId ;
153- }
154-
155- /** Capture a message for this scope. */
156- public captureEvent ( event : Event , hint ?: EventHint ) : string {
157- const eventId = hint && hint . event_id ? hint . event_id : uuid4 ( ) ;
158-
159- getClient ( ) . captureEvent ( event , { ...hint , event_id : eventId } , this ) ;
160-
161- return eventId ;
162- }
163-
164- /** Get scope data for this scope only. */
165- public getOwnScopeData ( ) : ScopeData {
166- return super . getScopeData ( ) ;
167- }
168- }
169-
17054function getScopes ( ) : CurrentScopes {
17155 const carrier = getGlobalCarrier ( ) ;
17256
@@ -184,8 +68,8 @@ function getScopes(): CurrentScopes {
18468function getGlobalCurrentScopes ( carrier : SentryCarrier ) : CurrentScopes {
18569 if ( ! carrier . scopes ) {
18670 carrier . scopes = {
187- scope : new Scope ( ) ,
188- isolationScope : new Scope ( ) ,
71+ scope : new ScopeClass ( ) ,
72+ isolationScope : new ScopeClass ( ) ,
18973 } ;
19074 }
19175
0 commit comments