Skip to content
Closed
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
6 changes: 3 additions & 3 deletions packages/core/src/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand All @@ -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);
}
1 change: 1 addition & 0 deletions packages/core/src/carrier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface SentryCarrier {
acs?: AsyncContextStrategy;
stack?: AsyncContextStack;

staticApiScope?: Scope;
globalScope?: Scope;
defaultIsolationScope?: Scope;
defaultCurrentScope?: Scope;
Expand Down
24 changes: 23 additions & 1 deletion packages/core/src/currentScopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down