MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / withScope

Function withScope

packages/core/src/currentScopes.ts:73–91  ·  view source on GitHub ↗
(
  ...rest: [callback: (scope: Scope) => T] | [scope: Scope | undefined, callback: (scope: Scope) => T]
)

Source from the content-addressed store, hash-verified

71 * Either creates a new active scope, or sets the given scope as active scope in the given callback.
72 */
73export function withScope<T>(
74 ...rest: [callback: (scope: Scope) => T] | [scope: Scope | undefined, callback: (scope: Scope) => T]
75): T {
76 const carrier = getMainCarrier();
77 const acs = getAsyncContextStrategy(carrier);
78
79 // If a scope is defined, we want to make this the active scope instead of the default one
80 if (rest.length === 2) {
81 const [scope, callback] = rest;
82
83 if (!scope) {
84 return acs.withScope(callback);
85 }
86
87 return acs.withSetScope(scope, callback);
88 }
89
90 return acs.withScope(rest[0]);
91}
92
93/**
94 * Attempts to fork the current isolation scope and the current scope based on the current async context strategy. If no

Callers 15

captureToolErrorFunction · 0.90
scope.test.tsFile · 0.90
feedback.test.tsFile · 0.90
trace.test.tsFile · 0.90
_getTraceInfoFromScopeFunction · 0.90
consoleHandlerFunction · 0.90
bindListenerToScopeFunction · 0.90
startSpanFunction · 0.90
startSpanManualFunction · 0.90

Calls 3

getMainCarrierFunction · 0.90
getAsyncContextStrategyFunction · 0.90
withScopeMethod · 0.80

Tested by

no test coverage detected