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;

0 commit comments

Comments
 (0)