Skip to content

Commit 5c35031

Browse files
authored
feat(v7/types): Deprecate Hub interface (#11530)
This PR deprecates the `Hub` interface as a continuation of #11528 where we deprecated the Hub class. The difference here is that the interface will stay deprecated throughout v8 so that we can shim the infamous `getCurrentHub` API. Most other usages of the interface should already be removed in v8/`develop` 🤞
1 parent 220580f commit 5c35031

File tree

27 files changed

+67
-6
lines changed

27 files changed

+67
-6
lines changed

packages/core/src/hub.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export interface Carrier {
115115
* themselves and will also be removed in version 8. More information:
116116
* - [Migration Guide](https://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#deprecate-hub)
117117
*/
118+
// eslint-disable-next-line deprecation/deprecation
118119
export class Hub implements HubInterface {
119120
/** Is a {@link Layer}[] containing the client and scope */
120121
private readonly _stack: Layer[];

packages/core/src/utils/isSentryRequestUrl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Client, DsnComponents, Hub } from '@sentry/types';
66
*
77
* TODO(v8): Remove Hub fallback type
88
*/
9+
// eslint-disable-next-line deprecation/deprecation
910
export function isSentryRequestUrl(url: string, hubOrClient: Hub | Client | undefined): boolean {
1011
const client =
1112
hubOrClient && isHub(hubOrClient)
@@ -34,6 +35,7 @@ function removeTrailingSlash(str: string): string {
3435
return str[str.length - 1] === '/' ? str.slice(0, -1) : str;
3536
}
3637

38+
// eslint-disable-next-line deprecation/deprecation
3739
function isHub(hubOrClient: Hub | Client | undefined): hubOrClient is Hub {
3840
// eslint-disable-next-line deprecation/deprecation
3941
return (hubOrClient as Hub).getClient !== undefined;

packages/core/test/lib/utils/isSentryRequestUrl.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('isSentryRequestUrl', () => {
2121
getClient: () => {
2222
return client;
2323
},
24+
// eslint-disable-next-line deprecation/deprecation
2425
} as unknown as Hub;
2526

2627
// Works with hub passed

packages/integrations/test/reportingobserver.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const withScope = jest.fn(callback => {
1414

1515
const captureMessage = jest.fn();
1616

17+
// eslint-disable-next-line deprecation/deprecation
1718
const mockHub = {} as unknown as Hub;
1819

1920
const mockReportingObserverConstructor = jest.fn();

packages/node-experimental/src/integrations/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export class Http implements Integration {
173173
/**
174174
* @inheritDoc
175175
*/
176+
// eslint-disable-next-line deprecation/deprecation
176177
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void, _getCurrentHub: () => Hub): void {
177178
// No need to instrument if we don't want to track anything
178179
if (!this._breadcrumbs && this._spans === false) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function getGlobalCarrier(): SentryCarrier {
2727
* Calls global extension method and binding current instance to the function call
2828
*/
2929
// @ts-expect-error Function lacks ending return statement and return type does not include 'undefined'. ts(2366)
30-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
30+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,deprecation/deprecation
3131
export function callExtensionMethod<T>(hub: Hub, method: string, ...args: any[]): T {
3232
const carrier = getGlobalCarrier();
3333

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function setupGlobalHub(): void {
4040
/**
4141
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.
4242
*/
43+
// eslint-disable-next-line deprecation/deprecation
4344
export function getCurrentHub(): Hub {
4445
return {
4546
isOlderThan(_version: number): boolean {
@@ -88,6 +89,7 @@ export function getCurrentHub(): Hub {
8889
// eslint-disable-next-line deprecation/deprecation
8990
configureScope: configureScope,
9091

92+
// eslint-disable-next-line deprecation/deprecation
9193
run(callback: (hub: Hub) => void): void {
9294
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9395
return withScope(() => callback(this as any));
@@ -142,6 +144,7 @@ export function getCurrentHub(): Hub {
142144
*
143145
* @returns The old replaced hub
144146
*/
147+
// eslint-disable-next-line deprecation/deprecation
145148
export function makeMain(hub: Hub): Hub {
146149
// eslint-disable-next-line no-console
147150
console.warn('makeMain is a noop in @sentry/node-experimental. Use `setCurrentClient` instead.');

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface AsyncContextStrategy {
5454
getScopes: () => CurrentScopes | undefined;
5555

5656
/** This is here for legacy reasons. */
57+
// eslint-disable-next-line deprecation/deprecation
5758
getCurrentHub: () => Hub;
5859

5960
/**
@@ -67,6 +68,7 @@ export interface SentryCarrier {
6768
acs?: AsyncContextStrategy;
6869

6970
// hub is here for legacy reasons
71+
// eslint-disable-next-line deprecation/deprecation
7072
hub?: Hub;
7173

7274
extensions?: {

packages/node/test/eventbuilders.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('eventFromUnknownInput', () => {
6969
return { normalizeDepth: 6 };
7070
},
7171
}),
72+
// eslint-disable-next-line deprecation/deprecation
7273
} as unknown as Hub;
7374
});
7475

packages/opentelemetry-node/src/utils/captureExceptionForTimedEvent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { isString } from '@sentry/utils';
77
* Maybe capture a Sentry exception for an OTEL timed event.
88
* This will check if the event is exception-like and in that case capture it as an exception.
99
*/
10+
// eslint-disable-next-line deprecation/deprecation
1011
export function maybeCaptureExceptionForTimedEvent(hub: Hub, event: TimedEvent, otelSpan?: OtelSpan): void {
1112
if (event.name !== 'exception') {
1213
return;

packages/opentelemetry-node/test/utils/captureExceptionForTimedEvent.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
1414
const captureException = jest.fn();
1515
const hub = {
1616
captureException,
17+
// eslint-disable-next-line deprecation/deprecation
1718
} as unknown as Hub;
1819

1920
maybeCaptureExceptionForTimedEvent(hub, event);
@@ -30,6 +31,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
3031
const captureException = jest.fn();
3132
const hub = {
3233
captureException,
34+
// eslint-disable-next-line deprecation/deprecation
3335
} as unknown as Hub;
3436

3537
maybeCaptureExceptionForTimedEvent(hub, event);
@@ -49,6 +51,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
4951
const captureException = jest.fn();
5052
const hub = {
5153
captureException,
54+
// eslint-disable-next-line deprecation/deprecation
5255
} as unknown as Hub;
5356

5457
maybeCaptureExceptionForTimedEvent(hub, event);
@@ -76,6 +79,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
7679
const captureException = jest.fn();
7780
const hub = {
7881
captureException,
82+
// eslint-disable-next-line deprecation/deprecation
7983
} as unknown as Hub;
8084

8185
maybeCaptureExceptionForTimedEvent(hub, event);
@@ -119,6 +123,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
119123
const captureException = jest.fn();
120124
const hub = {
121125
captureException,
126+
// eslint-disable-next-line deprecation/deprecation
122127
} as unknown as Hub;
123128

124129
maybeCaptureExceptionForTimedEvent(hub, event, span);

packages/opentelemetry/src/custom/transaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { uuid4 } from '@sentry/utils';
77
* This is a fork of core's tracing/hubextensions.ts _startTransaction,
88
* with some OTEL specifics.
99
*/
10+
// eslint-disable-next-line deprecation/deprecation
1011
export function startTransaction(hub: HubInterface, transactionContext: TransactionContext): Transaction {
1112
// eslint-disable-next-line deprecation/deprecation
1213
const client = hub.getClient();

packages/opentelemetry/src/utils/captureExceptionForTimedEvent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { isString } from '@sentry/utils';
77
* Maybe capture a Sentry exception for an OTEL timed event.
88
* This will check if the event is exception-like and in that case capture it as an exception.
99
*/
10+
// eslint-disable-next-line deprecation/deprecation
1011
export function maybeCaptureExceptionForTimedEvent(hub: Hub, event: TimedEvent, otelSpan?: OtelSpan): void {
1112
if (event.name !== 'exception') {
1213
return;

packages/opentelemetry/src/utils/contextData.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ export function setPropagationContextOnContext(context: Context, propagationCont
2323
* Try to get the Hub from the given OTEL context.
2424
* This requires a Context Manager that was wrapped with getWrappedContextManager.
2525
*/
26+
// eslint-disable-next-line deprecation/deprecation
2627
export function getHubFromContext(context: Context): Hub | undefined {
28+
// eslint-disable-next-line deprecation/deprecation
2729
return context.getValue(SENTRY_HUB_CONTEXT_KEY) as Hub | undefined;
2830
}
2931

3032
/**
3133
* Set a Hub on an OTEL context..
3234
* This will return a forked context with the Propagation Context set.
3335
*/
36+
// eslint-disable-next-line deprecation/deprecation
3437
export function setHubOnContext(context: Context, hub: Hub): Context {
3538
return context.setValue(SENTRY_HUB_CONTEXT_KEY, hub);
3639
}

packages/opentelemetry/src/utils/spanData.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { AbstractSpan } from '../types';
88
// and since we are using weakmaps, we do not need to clean up after ourselves
99
const SpanScope = new WeakMap<AbstractSpan, Scope>();
1010
const SpanFinishScope = new WeakMap<AbstractSpan, Scope>();
11+
// eslint-disable-next-line deprecation/deprecation
1112
const SpanHub = new WeakMap<AbstractSpan, Hub>();
1213
const SpanParent = new WeakMap<AbstractSpan, Span>();
1314
const SpanMetadata = new WeakMap<AbstractSpan, Partial<TransactionMetadata>>();
@@ -23,11 +24,13 @@ export function getSpanScope(span: AbstractSpan): Scope | undefined {
2324
}
2425

2526
/** Set the Sentry hub on an OTEL span. */
27+
// eslint-disable-next-line deprecation/deprecation
2628
export function setSpanHub(span: AbstractSpan, hub: Hub): void {
2729
SpanHub.set(span, hub);
2830
}
2931

3032
/** Get the Sentry hub of an OTEL span. */
33+
// eslint-disable-next-line deprecation/deprecation
3134
export function getSpanHub(span: AbstractSpan): Hub | undefined {
3235
return SpanHub.get(span);
3336
}

packages/opentelemetry/test/utils/captureExceptionForTimedEvent.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
1414
const captureException = jest.fn();
1515
const hub = {
1616
captureException,
17+
// eslint-disable-next-line deprecation/deprecation
1718
} as unknown as Hub;
1819

1920
maybeCaptureExceptionForTimedEvent(hub, event);
@@ -30,6 +31,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
3031
const captureException = jest.fn();
3132
const hub = {
3233
captureException,
34+
// eslint-disable-next-line deprecation/deprecation
3335
} as unknown as Hub;
3436

3537
maybeCaptureExceptionForTimedEvent(hub, event);
@@ -49,6 +51,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
4951
const captureException = jest.fn();
5052
const hub = {
5153
captureException,
54+
// eslint-disable-next-line deprecation/deprecation
5255
} as unknown as Hub;
5356

5457
maybeCaptureExceptionForTimedEvent(hub, event);
@@ -76,6 +79,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
7679
const captureException = jest.fn();
7780
const hub = {
7881
captureException,
82+
// eslint-disable-next-line deprecation/deprecation
7983
} as unknown as Hub;
8084

8185
maybeCaptureExceptionForTimedEvent(hub, event);
@@ -119,6 +123,7 @@ describe('maybeCaptureExceptionForTimedEvent', () => {
119123
const captureException = jest.fn();
120124
const hub = {
121125
captureException,
126+
// eslint-disable-next-line deprecation/deprecation
122127
} as unknown as Hub;
123128

124129
maybeCaptureExceptionForTimedEvent(hub, event, span);

packages/profiling-node/src/hubextensions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { isValidSampleRate } from './utils';
1010
export const MAX_PROFILE_DURATION_MS = 30 * 1000;
1111

1212
type StartTransaction = (
13+
// eslint-disable-next-line deprecation/deprecation
1314
this: Hub,
1415
transactionContext: TransactionContext,
1516
customSamplingContext?: CustomSamplingContext,
@@ -142,6 +143,7 @@ export function stopTransactionProfile(
142143
*/
143144
export function __PRIVATE__wrapStartTransactionWithProfiling(startTransaction: StartTransaction): StartTransaction {
144145
return function wrappedStartTransaction(
146+
// eslint-disable-next-line deprecation/deprecation
145147
this: Hub,
146148
transactionContext: TransactionContext,
147149
customSamplingContext?: CustomSamplingContext,

packages/profiling-node/src/integration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class ProfilingIntegration implements Integration {
5555
* @inheritDoc
5656
*/
5757
public readonly name: string;
58+
// eslint-disable-next-line deprecation/deprecation
5859
public getCurrentHub?: () => Hub;
5960

6061
public constructor() {
@@ -64,6 +65,7 @@ export class ProfilingIntegration implements Integration {
6465
/**
6566
* @inheritDoc
6667
*/
68+
// eslint-disable-next-line deprecation/deprecation
6769
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
6870
this.getCurrentHub = getCurrentHub;
6971
// eslint-disable-next-line deprecation/deprecation

packages/profiling-node/test/hubextensions.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function makeHubMock({
4747
}: {
4848
profilesSampleRate: number | undefined;
4949
client?: Partial<NodeClient>;
50+
// eslint-disable-next-line deprecation/deprecation
5051
}): Hub {
5152
return {
5253
getClient: jest.fn().mockImplementation(() => {
@@ -59,6 +60,7 @@ function makeHubMock({
5960
...(client ?? {}),
6061
};
6162
}),
63+
// eslint-disable-next-line deprecation/deprecation
6264
} as unknown as Hub;
6365
}
6466

0 commit comments

Comments
 (0)