diff --git a/packages/core/src/breadcrumbs.ts b/packages/core/src/breadcrumbs.ts index 1cfad5d08fea..6d6377757322 100644 --- a/packages/core/src/breadcrumbs.ts +++ b/packages/core/src/breadcrumbs.ts @@ -1,6 +1,6 @@ import type { Breadcrumb, BreadcrumbHint } from '@sentry/types'; import { consoleSandbox, dateTimestampInSeconds } from '@sentry/utils'; -import { getClient, getIsolationScope } from './currentScopes'; +import { getClient, getStaticApiScope } from './currentScopes'; /** * Default maximum number of breadcrumbs added to an event. Can be overwritten @@ -16,7 +16,7 @@ const DEFAULT_BREADCRUMBS = 100; */ export function addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void { const client = getClient(); - const isolationScope = getIsolationScope(); + const scope = getStaticApiScope(); if (!client) return; @@ -36,5 +36,5 @@ export function addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): vo client.emit('beforeAddBreadcrumb', finalBreadcrumb, hint); } - isolationScope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs); + scope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs); } diff --git a/packages/core/src/carrier.ts b/packages/core/src/carrier.ts index 7442244223ca..19e68b3c72cf 100644 --- a/packages/core/src/carrier.ts +++ b/packages/core/src/carrier.ts @@ -19,6 +19,7 @@ interface SentryCarrier { acs?: AsyncContextStrategy; stack?: AsyncContextStack; + staticApiScope?: Scope; globalScope?: Scope; defaultIsolationScope?: Scope; defaultCurrentScope?: Scope; diff --git a/packages/core/src/currentScopes.ts b/packages/core/src/currentScopes.ts index 9472d48b71bf..9560a00f72cc 100644 --- a/packages/core/src/currentScopes.ts +++ b/packages/core/src/currentScopes.ts @@ -2,8 +2,9 @@ import type { Scope } from '@sentry/types'; import type { Client } from '@sentry/types'; import { getGlobalSingleton } from '@sentry/utils'; import { getAsyncContextStrategy } from './asyncContext'; -import { getMainCarrier } from './carrier'; +import { getMainCarrier, getSentryCarrier } from './carrier'; import { Scope as ScopeClass } from './scope'; +import { GLOBAL_OBJ } from '@sentry/utils'; /** * Get the currently active scope. @@ -32,6 +33,27 @@ export function getGlobalScope(): Scope { return getGlobalSingleton('globalScope', () => new ScopeClass()); } +/** + * You should never call this directly. It will be called by the SDK. + * Get the default scope which all static `Sentry.*` functions use. + * + * @internal + */ +export function getStaticApiScope(): Scope { + return getGlobalSingleton('staticApiScope', getIsolationScope); +} + +/** + * You should never call this directly. It will be called by the SDK. + * Sets the default scope which all static `Sentry.*` functions will use. + * + * @internal + */ +export function setStaticApiScope(scope: Scope): void { + const carrier = getSentryCarrier(GLOBAL_OBJ); + carrier.staticApiScope = scope; +} + /** * Creates a new scope with and executes the given operation within. * The scope is automatically removed once the operation