Skip to content

Commit 5039e84

Browse files
authored
feat(core): Move more scope globals to __SENTRY__ (#11074)
This PR moves `defaultCurrentScope` and `defaultIsolationScope` to the `__SENTRY__` global.
1 parent 2333b3f commit 5039e84

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

packages/core/src/hub.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
SeverityLevel,
1818
User,
1919
} from '@sentry/types';
20+
import { getGlobalSingleton } from '@sentry/utils';
2021
import { GLOBAL_OBJ, consoleSandbox, dateTimestampInSeconds, isThenable, logger, uuid4 } from '@sentry/utils';
2122

2223
import type { AsyncContextStrategy, Carrier } from './asyncContext';
@@ -574,25 +575,14 @@ export function getCurrentHub(): HubInterface {
574575
return acs.getCurrentHub() || getGlobalHub();
575576
}
576577

577-
let defaultCurrentScope: Scope | undefined;
578-
let defaultIsolationScope: Scope | undefined;
579-
580578
/** Get the default current scope. */
581579
export function getDefaultCurrentScope(): Scope {
582-
if (!defaultCurrentScope) {
583-
defaultCurrentScope = new Scope();
584-
}
585-
586-
return defaultCurrentScope;
580+
return getGlobalSingleton('defaultCurrentScope', () => new Scope());
587581
}
588582

589583
/** Get the default isolation scope. */
590584
export function getDefaultIsolationScope(): Scope {
591-
if (!defaultIsolationScope) {
592-
defaultIsolationScope = new Scope();
593-
}
594-
595-
return defaultIsolationScope;
585+
return getGlobalSingleton('defaultIsolationScope', () => new Scope());
596586
}
597587

598588
/**

packages/utils/src/worldwide.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface InternalGlobal {
5555
[key: string]: Function;
5656
};
5757
globalScope: Scope | undefined;
58+
defaultCurrentScope: Scope | undefined;
59+
defaultIsolationScope: Scope | undefined;
5860
globalMetricsAggregators: WeakMap<Client, MetricsAggregator> | undefined;
5961
};
6062
/**

0 commit comments

Comments
 (0)