Skip to content

Commit 7eed53f

Browse files
committed
fix hub & scope types
1 parent 7c49e53 commit 7eed53f

File tree

18 files changed

+41
-36
lines changed

18 files changed

+41
-36
lines changed

packages/core/src/exports.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ export function withScope<T>(scope: ScopeInterface | undefined, callback: (scope
158158
* Either creates a new active scope, or sets the given scope as active scope in the given callback.
159159
*/
160160
export function withScope<T>(
161-
...rest: [callback: (scope: Scope) => T] | [scope: ScopeInterface | undefined, callback: (scope: ScopeInterface) => T]
161+
...rest:
162+
| [callback: (scope: ScopeInterface) => T]
163+
| [scope: ScopeInterface | undefined, callback: (scope: ScopeInterface) => T]
162164
): T {
163165
// eslint-disable-next-line deprecation/deprecation
164166
const hub = getCurrentHub() as Hub;

packages/core/src/hub.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
Integration,
1313
IntegrationClass,
1414
Primitive,
15+
Scope as ScopeInterface,
1516
Session,
1617
SessionContext,
1718
SeverityLevel,
@@ -51,7 +52,7 @@ const DEFAULT_BREADCRUMBS = 100;
5152
*/
5253
export interface Layer {
5354
client?: Client;
54-
scope: Scope;
55+
scope: ScopeInterface;
5556
}
5657

5758
/**
@@ -61,7 +62,7 @@ export class Hub implements HubInterface {
6162
/** Is a {@link Layer}[] containing the client and scope */
6263
private readonly _stack: Layer[];
6364

64-
private _isolationScope: Scope;
65+
private _isolationScope: ScopeInterface;
6566

6667
/**
6768
* Creates a new instance of the hub, will push one {@link Layer} into the
@@ -113,8 +114,8 @@ export class Hub implements HubInterface {
113114
*/
114115
public constructor(
115116
client?: Client,
116-
scope?: Scope,
117-
isolationScope?: Scope,
117+
scope?: ScopeInterface,
118+
isolationScope?: ScopeInterface,
118119
private readonly _version: number = API_VERSION,
119120
) {
120121
let assignedScope;
@@ -178,7 +179,7 @@ export class Hub implements HubInterface {
178179
*
179180
* @deprecated Use `withScope` instead.
180181
*/
181-
public pushScope(): Scope {
182+
public pushScope(): ScopeInterface {
182183
// We want to clone the content of prev scope
183184
// eslint-disable-next-line deprecation/deprecation
184185
const scope = this.getScope().clone();
@@ -208,7 +209,7 @@ export class Hub implements HubInterface {
208209
*
209210
* @deprecated Use `Sentry.withScope()` instead.
210211
*/
211-
public withScope<T>(callback: (scope: Scope) => T): T {
212+
public withScope<T>(callback: (scope: ScopeInterface) => T): T {
212213
// eslint-disable-next-line deprecation/deprecation
213214
const scope = this.pushScope();
214215

@@ -257,15 +258,15 @@ export class Hub implements HubInterface {
257258
*
258259
* @deprecated Use `Sentry.getCurrentScope()` instead.
259260
*/
260-
public getScope(): Scope {
261+
public getScope(): ScopeInterface {
261262
// eslint-disable-next-line deprecation/deprecation
262263
return this.getStackTop().scope;
263264
}
264265

265266
/**
266267
* @deprecated Use `Sentry.getIsolationScope()` instead.
267268
*/
268-
public getIsolationScope(): Scope {
269+
public getIsolationScope(): ScopeInterface {
269270
return this._isolationScope;
270271
}
271272

packages/core/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { consoleSandbox, logger } from '@sentry/utils';
33
import { getCurrentScope } from './currentScopes';
44

55
import { DEBUG_BUILD } from './debug-build';
6-
import type { Hub} from './hub';
6+
import type { Hub } from './hub';
77
import { getCurrentHub } from './hub';
88

99
/** A class object that can instantiate Client objects. */

packages/core/src/tracing/hubextensions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type { ClientOptions, CustomSamplingContext, TransactionContext } from '@sentry/types';
1+
import type { ClientOptions, CustomSamplingContext, Hub, TransactionContext } from '@sentry/types';
22
import { logger } from '@sentry/utils';
33
import { getMainCarrier } from '../asyncContext';
44

55
import { DEBUG_BUILD } from '../debug-build';
6-
import type { Hub } from '../hub';
76
import { spanToTraceHeader } from '../utils/spanUtils';
87
import { registerErrorInstrumentation } from './errors';
98
import { IdleTransaction } from './idletransaction';

packages/core/src/tracing/idletransaction.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/* eslint-disable max-lines */
2-
import type { SpanTimeInput, TransactionContext } from '@sentry/types';
2+
import type { Hub, SpanTimeInput, TransactionContext } from '@sentry/types';
33
import { logger, timestampInSeconds } from '@sentry/utils';
44

55
import { DEBUG_BUILD } from '../debug-build';
6-
import type { Hub } from '../hub';
76
import { spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';
87
import type { Span } from './span';
98
import { SpanRecorder } from './span';

packages/core/src/tracing/transaction.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
Context,
33
Contexts,
44
DynamicSamplingContext,
5-
Hub as HubInterface,
5+
Hub,
66
MeasurementUnit,
77
Measurements,
88
SpanTimeInput,
@@ -14,7 +14,6 @@ import type {
1414
import { dropUndefinedKeys, logger } from '@sentry/utils';
1515

1616
import { DEBUG_BUILD } from '../debug-build';
17-
import type { Hub } from '../hub';
1817
import { getCurrentHub } from '../hub';
1918
import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary';
2019
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
@@ -28,7 +27,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
2827
/**
2928
* The reference to the current hub.
3029
*/
31-
public _hub: HubInterface;
30+
public _hub: Hub;
3231

3332
protected _name: string;
3433

packages/core/src/utils/prepareEvent.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function prepareEvent(
4848
options: ClientOptions,
4949
event: Event,
5050
hint: EventHint,
51-
scope?: Scope,
51+
scope?: ScopeInterface,
5252
client?: Client,
5353
isolationScope?: ScopeInterface,
5454
): PromiseLike<Event | null> {
@@ -343,7 +343,10 @@ function normalizeEvent(event: Event | null, depth: number, maxBreadth: number):
343343
return normalized;
344344
}
345345

346-
function getFinalScope(scope: Scope | undefined, captureContext: CaptureContext | undefined): Scope | undefined {
346+
function getFinalScope(
347+
scope: ScopeInterface | undefined,
348+
captureContext: CaptureContext | undefined,
349+
): ScopeInterface | undefined {
347350
if (!captureContext) {
348351
return scope;
349352
}

packages/feedback/src/util/prepareFeedbackEvent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { Scope } from '@sentry/core';
21
import { getIsolationScope } from '@sentry/core';
32
import { prepareEvent } from '@sentry/core';
4-
import type { Client, FeedbackEvent } from '@sentry/types';
3+
import type { Client, FeedbackEvent, Scope } from '@sentry/types';
54

65
interface PrepareFeedbackEventParams {
76
client: Client;

packages/node-experimental/src/sdk/hub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function getCurrentHub(): Hub {
5858
},
5959

6060
withScope,
61-
getClient,
61+
getClient: <C extends Client>() => getClient() as C | undefined,
6262
getScope: getCurrentScope,
6363
getIsolationScope,
6464
captureException: (exception: unknown, hint?: EventHint) => {

packages/node/src/async/domain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as domain from 'domain';
2-
import type { Carrier, Hub, RunWithAsyncContextOptions } from '@sentry/core';
2+
import type { Carrier, RunWithAsyncContextOptions } from '@sentry/core';
33
import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy, setHubOnCarrier } from '@sentry/core';
4+
import type { Hub } from '@sentry/types';
45

56
function getActiveDomain<T>(): T | undefined {
67
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any

packages/node/src/async/hooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { Carrier, Hub, RunWithAsyncContextOptions } from '@sentry/core';
1+
import type { Carrier, RunWithAsyncContextOptions } from '@sentry/core';
22
import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy } from '@sentry/core';
3+
import type { Hub } from '@sentry/types';
34
import * as async_hooks from 'async_hooks';
45

56
interface AsyncLocalStorage<T> {

packages/opentelemetry/src/contextManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { Context, ContextManager } from '@opentelemetry/api';
22
import { Hub } from '@sentry/core';
33
import { getCurrentHub } from '@sentry/core';
4+
import type { Hub as HubInterface } from '@sentry/types';
45
import { SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY } from './constants';
56

67
import { setHubOnContext } from './utils/contextData';
78

8-
function createNewHub(parent: Hub | undefined, shouldForkIsolationScope: boolean): Hub {
9+
function createNewHub(parent: HubInterface | undefined, shouldForkIsolationScope: boolean): Hub {
910
if (parent) {
1011
// eslint-disable-next-line deprecation/deprecation
1112
const client = parent.getClient();

packages/react/src/errorboundary.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { ReportDialogOptions, Scope } from '@sentry/browser';
1+
import type { ReportDialogOptions } from '@sentry/browser';
22
import { captureException, getClient, showReportDialog, withScope } from '@sentry/browser';
3+
import type { Scope } from '@sentry/types';
34
import { isError, logger } from '@sentry/utils';
45
import hoistNonReactStatics from 'hoist-non-react-statics';
56
import * as React from 'react';

packages/remix/src/utils/instrumentServer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import {
1212
spanToJSON,
1313
spanToTraceHeader,
1414
} from '@sentry/core';
15-
import type { Hub } from '@sentry/node';
1615
import { captureException, getCurrentHub } from '@sentry/node';
17-
import type { Transaction, TransactionSource, WrappedFunction } from '@sentry/types';
16+
import type { Hub, Transaction, TransactionSource, WrappedFunction } from '@sentry/types';
1817
import {
1918
addExceptionMechanism,
2019
dynamicSamplingContextToSentryBaggageHeader,

packages/replay/src/util/prepareReplayEvent.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { IntegrationIndex, Scope } from '@sentry/core';
2-
import { getIsolationScope } from '@sentry/core';
3-
import { prepareEvent } from '@sentry/core';
4-
import type { Client, EventHint, ReplayEvent } from '@sentry/types';
1+
import type { IntegrationIndex } from '@sentry/core';
2+
import { getIsolationScope, prepareEvent } from '@sentry/core';
3+
import type { Client, EventHint, ReplayEvent, Scope } from '@sentry/types';
54

65
/**
76
* Prepare a replay event & enrich it with the SDK metadata.

packages/serverless/src/awslambda.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { existsSync } from 'fs';
22
import { hostname } from 'os';
33
import { basename, resolve } from 'path';
44
import { types } from 'util';
5-
import type { NodeOptions, Scope } from '@sentry/node';
5+
import type { NodeOptions } from '@sentry/node';
66
import { SDK_VERSION } from '@sentry/node';
77
import {
88
captureException,
@@ -16,7 +16,7 @@ import {
1616
startSpanManual,
1717
withScope,
1818
} from '@sentry/node';
19-
import type { Integration, Options, SdkMetadata, Span } from '@sentry/types';
19+
import type { Integration, Options, Scope, SdkMetadata, Span } from '@sentry/types';
2020
import { isString, logger } from '@sentry/utils';
2121
import type { Context, Handler } from 'aws-lambda';
2222
import { performance } from 'perf_hooks';

packages/types/src/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface Scope {
5959
*
6060
* It is generally recommended to use the global function `Sentry.getClient()` instead, unless you know what you are doing.
6161
*/
62-
getClient(): Client | undefined;
62+
getClient<C extends Client>(): C | undefined;
6363

6464
/** Add new event processor that will be called after {@link applyToEvent}. */
6565
addEventProcessor(callback: EventProcessor): this;

packages/vercel-edge/src/async.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { Carrier, Hub, RunWithAsyncContextOptions } from '@sentry/core';
1+
import type { Carrier, RunWithAsyncContextOptions } from '@sentry/core';
22
import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy } from '@sentry/core';
3+
import type { Hub } from '@sentry/types';
34
import { GLOBAL_OBJ, logger } from '@sentry/utils';
45

56
import { DEBUG_BUILD } from './debug-build';

0 commit comments

Comments
 (0)