Skip to content

Commit a16d7ef

Browse files
committed
ref(core)!: Remove Scope type interface in favor of using Scope class
fix more tests fix deno types build??
1 parent b9899bb commit a16d7ef

35 files changed

+209
-422
lines changed

docs/migration/v8-to-v9.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
151151
The SDK no longer contains these statements.
152152
Let us know if this is causing issues in your setup by opening an issue on GitHub.
153153

154+
## 6. Type Changes
155+
156+
In v8, types have been exported from `@sentry/types`, while implementations have been exported from other classes.
157+
This lead to some duplication, where we had to keep an interface in `@sentry/types`, while the implementation mirroring that interface was kept e.g. in `@sentry/core`.
158+
Since in v9 the types have been merged into `@sentry/core`, we can get rid of some of this duplication. This means that certain things that used to be a separate interface, will not expect an actual instance of the class/concrete implementation. This should not affect most users, unless you relied on passing things with a similar shape to internal methods. The following types are affected:
159+
160+
- `Scope` now always expects the `Scope` class
161+
154162
# Deprecations in 8.x
155163

156164
TBD (Copy over from migrations list we collected)

packages/core/src/asyncContext/stackStrategy.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { getDefaultCurrentScope, getDefaultIsolationScope } from '../defaultScopes';
22
import { Scope } from '../scope';
3-
import type { Client, Scope as ScopeInterface } from '../types-hoist';
3+
import type { Client } from '../types-hoist';
44
import { isThenable } from '../utils-hoist/is';
55
import { getMainCarrier, getSentryCarrier } from './../carrier';
66
import type { AsyncContextStrategy } from './types';
77

88
interface Layer {
99
client?: Client;
10-
scope: ScopeInterface;
10+
scope: Scope;
1111
}
1212

1313
/**
1414
* This is an object that holds a stack of scopes.
1515
*/
1616
export class AsyncContextStack {
1717
private readonly _stack: [Layer, ...Layer[]];
18-
private _isolationScope: ScopeInterface;
18+
private _isolationScope: Scope;
1919

20-
public constructor(scope?: ScopeInterface, isolationScope?: ScopeInterface) {
20+
public constructor(scope?: Scope, isolationScope?: Scope) {
2121
let assignedScope;
2222
if (!scope) {
2323
assignedScope = new Scope();
@@ -40,7 +40,7 @@ export class AsyncContextStack {
4040
/**
4141
* Fork a scope for the stack.
4242
*/
43-
public withScope<T>(callback: (scope: ScopeInterface) => T): T {
43+
public withScope<T>(callback: (scope: Scope) => T): T {
4444
const scope = this._pushScope();
4545

4646
let maybePromiseResult: T;
@@ -79,14 +79,14 @@ export class AsyncContextStack {
7979
/**
8080
* Returns the scope of the top stack.
8181
*/
82-
public getScope(): ScopeInterface {
82+
public getScope(): Scope {
8383
return this.getStackTop().scope;
8484
}
8585

8686
/**
8787
* Get the isolation scope for the stack.
8888
*/
89-
public getIsolationScope(): ScopeInterface {
89+
public getIsolationScope(): Scope {
9090
return this._isolationScope;
9191
}
9292

@@ -100,7 +100,7 @@ export class AsyncContextStack {
100100
/**
101101
* Push a scope to the stack.
102102
*/
103-
private _pushScope(): ScopeInterface {
103+
private _pushScope(): Scope {
104104
// We want to clone the content of prev scope
105105
const scope = this.getScope().clone();
106106
this._stack.push({
@@ -130,19 +130,19 @@ function getAsyncContextStack(): AsyncContextStack {
130130
return (sentry.stack = sentry.stack || new AsyncContextStack(getDefaultCurrentScope(), getDefaultIsolationScope()));
131131
}
132132

133-
function withScope<T>(callback: (scope: ScopeInterface) => T): T {
133+
function withScope<T>(callback: (scope: Scope) => T): T {
134134
return getAsyncContextStack().withScope(callback);
135135
}
136136

137-
function withSetScope<T>(scope: ScopeInterface, callback: (scope: ScopeInterface) => T): T {
137+
function withSetScope<T>(scope: Scope, callback: (scope: Scope) => T): T {
138138
const stack = getAsyncContextStack() as AsyncContextStack;
139139
return stack.withScope(() => {
140140
stack.getStackTop().scope = scope;
141141
return callback(scope);
142142
});
143143
}
144144

145-
function withIsolationScope<T>(callback: (isolationScope: ScopeInterface) => T): T {
145+
function withIsolationScope<T>(callback: (isolationScope: Scope) => T): T {
146146
return getAsyncContextStack().withScope(() => {
147147
return callback(getAsyncContextStack().getIsolationScope());
148148
});
@@ -156,7 +156,7 @@ export function getStackAsyncContextStrategy(): AsyncContextStrategy {
156156
withIsolationScope,
157157
withScope,
158158
withSetScope,
159-
withSetIsolationScope: <T>(_isolationScope: ScopeInterface, callback: (isolationScope: ScopeInterface) => T) => {
159+
withSetIsolationScope: <T>(_isolationScope: Scope, callback: (isolationScope: Scope) => T) => {
160160
return withIsolationScope(callback);
161161
},
162162
getCurrentScope: () => getAsyncContextStack().getScope(),

packages/core/src/asyncContext/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Scope } from '../types-hoist';
1+
import type { Scope } from '../scope';
22
import type { getTraceData } from '../utils/traceData';
33
import type {
44
startInactiveSpan,

packages/core/src/carrier.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { AsyncContextStack } from './asyncContext/stackStrategy';
22
import type { AsyncContextStrategy } from './asyncContext/types';
3-
import type { Client, Integration, MetricsAggregator, Scope } from './types-hoist';
3+
import type { Scope } from './scope';
4+
import type { Client, Integration, MetricsAggregator } from './types-hoist';
45
import { SDK_VERSION } from './utils-hoist/version';
56
import { GLOBAL_OBJ } from './utils-hoist/worldwide';
67

packages/core/src/currentScopes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getAsyncContextStrategy } from './asyncContext';
22
import { getMainCarrier } from './carrier';
3-
import { Scope as ScopeClass } from './scope';
4-
import type { Client, Scope, TraceContext } from './types-hoist';
3+
import { Scope } from './scope';
4+
import type { Client, TraceContext } from './types-hoist';
55
import { dropUndefinedKeys } from './utils-hoist/object';
66
import { getGlobalSingleton } from './utils-hoist/worldwide';
77

@@ -29,7 +29,7 @@ export function getIsolationScope(): Scope {
2929
* This scope is applied to _all_ events.
3030
*/
3131
export function getGlobalScope(): Scope {
32-
return getGlobalSingleton('globalScope', () => new ScopeClass());
32+
return getGlobalSingleton('globalScope', () => new Scope());
3333
}
3434

3535
/**

packages/core/src/defaultScopes.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { Scope as ScopeClass } from './scope';
2-
import type { Scope } from './types-hoist';
1+
import { Scope } from './scope';
32
import { getGlobalSingleton } from './utils-hoist/worldwide';
43

54
/** Get the default current scope. */
65
export function getDefaultCurrentScope(): Scope {
7-
return getGlobalSingleton('defaultCurrentScope', () => new ScopeClass());
6+
return getGlobalSingleton('defaultCurrentScope', () => new Scope());
87
}
98

109
/** Get the default isolation scope. */
1110
export function getDefaultIsolationScope(): Scope {
12-
return getGlobalSingleton('defaultIsolationScope', () => new ScopeClass());
11+
return getGlobalSingleton('defaultIsolationScope', () => new Scope());
1312
}

packages/core/src/exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {
2-
CaptureContext,
32
CheckIn,
43
Event,
54
EventHint,
@@ -18,6 +17,7 @@ import type {
1817
import { DEFAULT_ENVIRONMENT } from './constants';
1918
import { getClient, getCurrentScope, getIsolationScope, withIsolationScope } from './currentScopes';
2019
import { DEBUG_BUILD } from './debug-build';
20+
import type { CaptureContext } from './scope';
2121
import { closeSession, makeSession, updateSession } from './session';
2222
import { isThenable } from './utils-hoist/is';
2323
import { logger } from './utils-hoist/logger';

packages/core/src/fetch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import type { Scope } from './scope';
12
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes';
23
import { SPAN_STATUS_ERROR, setHttpStatus, startInactiveSpan } from './tracing';
34
import { SentryNonRecordingSpan } from './tracing/sentryNonRecordingSpan';
4-
import type { Client, HandlerDataFetch, Scope, Span, SpanOrigin } from './types-hoist';
5+
import type { Client, HandlerDataFetch, Span, SpanOrigin } from './types-hoist';
56
import { SENTRY_BAGGAGE_KEY_PREFIX } from './utils-hoist/baggage';
67
import { isInstanceOf } from './utils-hoist/is';
78
import { parseUrl } from './utils-hoist/url';

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export { makeSession, closeSession, updateSession } from './session';
5050
// eslint-disable-next-line deprecation/deprecation
5151
export { SessionFlusher } from './sessionflusher';
5252
export { Scope } from './scope';
53+
export type { CaptureContext, ScopeContext, ScopeData } from './scope';
5354
export { notifyEventProcessors } from './eventProcessors';
5455
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
5556
export { BaseClient } from './baseclient';

packages/core/src/integrations/captureconsole.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { getClient, withScope } from '../currentScopes';
22
import { captureException, captureMessage } from '../exports';
33
import { defineIntegration } from '../integration';
4-
import type { CaptureContext, IntegrationFn } from '../types-hoist';
4+
import type { CaptureContext } from '../scope';
5+
import type { IntegrationFn } from '../types-hoist';
56
import { addConsoleInstrumentationHandler } from '../utils-hoist/instrument/console';
67
import { CONSOLE_LEVELS } from '../utils-hoist/logger';
78
import { addExceptionMechanism } from '../utils-hoist/misc';

0 commit comments

Comments
 (0)