Skip to content

feat(core): Move more scope globals to __SENTRY__ #11074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions packages/core/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
SeverityLevel,
User,
} from '@sentry/types';
import { getGlobalSingleton } from '@sentry/utils';
import { GLOBAL_OBJ, consoleSandbox, dateTimestampInSeconds, isThenable, logger, uuid4 } from '@sentry/utils';

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

let defaultCurrentScope: Scope | undefined;
let defaultIsolationScope: Scope | undefined;

/** Get the default current scope. */
export function getDefaultCurrentScope(): Scope {
if (!defaultCurrentScope) {
defaultCurrentScope = new Scope();
}

return defaultCurrentScope;
return getGlobalSingleton('defaultCurrentScope', () => new Scope());
}

/** Get the default isolation scope. */
export function getDefaultIsolationScope(): Scope {
if (!defaultIsolationScope) {
defaultIsolationScope = new Scope();
}

return defaultIsolationScope;
return getGlobalSingleton('defaultIsolationScope', () => new Scope());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/src/worldwide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export interface InternalGlobal {
[key: string]: Function;
};
globalScope: Scope | undefined;
defaultCurrentScope: Scope | undefined;
defaultIsolationScope: Scope | undefined;
globalMetricsAggregators: WeakMap<Client, MetricsAggregator> | undefined;
};
/**
Expand Down