Skip to content

Commit 38b0dae

Browse files
authored
feat(core): Remove most Hub class exports (#11536)
Remove top-level exports of the `Hub` class from all SDK packages. The only package that still exports it is core for now because we temporarily still need the class until we shimmed the return value of `getCurrentHub`. Furthermore also deprecate the `Hub` interface. However, this interface will not be removed in v8 (prob v9) to keep support for `getCurrentHub` during the v8 life cycle.
1 parent 3a1f028 commit 38b0dae

File tree

22 files changed

+37
-21
lines changed

22 files changed

+37
-21
lines changed

dev-packages/browser-integration-tests/suites/manual-client/browser-context/init.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
BrowserClient,
3-
Hub,
3+
Scope,
44
breadcrumbsIntegration,
55
dedupeIntegration,
66
defaultStackParser,
@@ -31,6 +31,9 @@ const client = new BrowserClient({
3131
integrations,
3232
});
3333

34-
const hub = new Hub(client);
34+
const scope = new Scope();
35+
scope.setClient(client);
3536

36-
hub.captureException(new Error('test client'));
37+
client.init();
38+
39+
scope.captureException(new Error('test client'));

packages/astro/src/index.server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export {
2323
getCurrentScope,
2424
getGlobalScope,
2525
getIsolationScope,
26-
Hub,
2726
setCurrentClient,
2827
Scope,
2928
SDK_VERSION,

packages/aws-serverless/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export {
1818
getCurrentScope,
1919
getGlobalScope,
2020
getIsolationScope,
21-
Hub,
2221
setCurrentClient,
2322
Scope,
2423
SDK_VERSION,

packages/browser/src/exports.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export {
3535
getCurrentScope,
3636
getIsolationScope,
3737
getGlobalScope,
38-
Hub,
3938
setCurrentClient,
4039
Scope,
4140
continueTrace,

packages/bun/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export {
3737
getCurrentScope,
3838
getGlobalScope,
3939
getIsolationScope,
40-
Hub,
4140
setCurrentClient,
4241
Scope,
4342
SDK_VERSION,

packages/core/src/asyncContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface AsyncContextStrategy {
1313
/**
1414
* Gets the currently active hub.
1515
*/
16+
// eslint-disable-next-line deprecation/deprecation
1617
getCurrentHub: () => Hub;
1718

1819
/**

packages/core/src/exports.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { GLOBAL_OBJ, isThenable, logger, timestampInSeconds, uuid4 } from '@sent
1919
import { DEFAULT_ENVIRONMENT } from './constants';
2020
import { getClient, getCurrentScope, getIsolationScope } from './currentScopes';
2121
import { DEBUG_BUILD } from './debug-build';
22-
import type { Hub } from './hub';
2322
import { closeSession, makeSession, updateSession } from './session';
2423
import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent';
2524
import { parseEventHintOrCaptureContext } from './utils/prepareEvent';
@@ -71,15 +70,15 @@ export function captureEvent(event: Event, hint?: EventHint): string {
7170
* @param context Any kind of data. This data will be normalized.
7271
*/
7372
// eslint-disable-next-line @typescript-eslint/no-explicit-any
74-
export function setContext(name: string, context: { [key: string]: any } | null): ReturnType<Hub['setContext']> {
73+
export function setContext(name: string, context: { [key: string]: any } | null): void {
7574
getIsolationScope().setContext(name, context);
7675
}
7776

7877
/**
7978
* Set an object that will be merged sent as extra data with the event.
8079
* @param extras Extras object to merge into current context.
8180
*/
82-
export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
81+
export function setExtras(extras: Extras): void {
8382
getIsolationScope().setExtras(extras);
8483
}
8584

@@ -88,15 +87,15 @@ export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
8887
* @param key String of extra
8988
* @param extra Any kind of data. This data will be normalized.
9089
*/
91-
export function setExtra(key: string, extra: Extra): ReturnType<Hub['setExtra']> {
90+
export function setExtra(key: string, extra: Extra): void {
9291
getIsolationScope().setExtra(key, extra);
9392
}
9493

9594
/**
9695
* Set an object that will be merged sent as tags data with the event.
9796
* @param tags Tags context object to merge into current context.
9897
*/
99-
export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['setTags']> {
98+
export function setTags(tags: { [key: string]: Primitive }): void {
10099
getIsolationScope().setTags(tags);
101100
}
102101

@@ -108,7 +107,7 @@ export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['set
108107
* @param key String key of tag
109108
* @param value Value of tag
110109
*/
111-
export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']> {
110+
export function setTag(key: string, value: Primitive): void {
112111
getIsolationScope().setTag(key, value);
113112
}
114113

@@ -117,7 +116,7 @@ export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']>
117116
*
118117
* @param user User context object to be set in the current context. Pass `null` to unset the user.
119118
*/
120-
export function setUser(user: User | null): ReturnType<Hub['setUser']> {
119+
export function setUser(user: User | null): void {
121120
getIsolationScope().setUser(user);
122121
}
123122

packages/core/src/getCurrentHubShim.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ import {
1616
/**
1717
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.
1818
*
19-
* @deprecated Use the methods directly.
19+
* @deprecated Use the methods directly from the top level Sentry API (e.g. `Sentry.withScope`)
20+
* For more information see our migration guide for
21+
* [replacing `getCurrentHub` and `Hub`](https://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#deprecate-hub)
22+
* usage
2023
*/
24+
// eslint-disable-next-line deprecation/deprecation
2125
export function getCurrentHubShim(): Hub {
2226
return {
2327
bindClient(client: Client): void {

packages/core/src/hub.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export interface Layer {
5555

5656
/**
5757
* @inheritDoc
58+
* @deprecated This class will be removed in v8 (tmp-deprecating so we're aware of where this is a problem)
5859
*/
60+
// eslint-disable-next-line deprecation/deprecation
5961
export class Hub implements HubInterface {
6062
/** Is a {@link Layer}[] containing the client and scope */
6163
private readonly _stack: Layer[];
@@ -503,6 +505,7 @@ export class Hub implements HubInterface {
503505
*
504506
* @deprecated Use the respective replacement method directly instead.
505507
*/
508+
// eslint-disable-next-line deprecation/deprecation
506509
export function getCurrentHub(): HubInterface {
507510
// Get main carrier (global for every environment)
508511
const carrier = getMainCarrier();
@@ -525,8 +528,10 @@ export function getDefaultIsolationScope(): Scope {
525528
* Get the global hub.
526529
* This will be removed during the v8 cycle and is only here to make migration easier.
527530
*/
531+
// eslint-disable-next-line deprecation/deprecation
528532
export function getGlobalHub(): HubInterface {
529533
const registry = getMainCarrier();
534+
// eslint-disable-next-line deprecation/deprecation
530535
const sentry = getSentryCarrier(registry) as { hub?: HubInterface };
531536

532537
// If there's no hub, or its an old API, assign a new one
@@ -560,6 +565,7 @@ function withScope<T>(callback: (scope: ScopeInterface) => T): T {
560565
}
561566

562567
function withSetScope<T>(scope: ScopeInterface, callback: (scope: ScopeInterface) => T): T {
568+
// eslint-disable-next-line deprecation/deprecation
563569
const hub = getGlobalHub() as Hub;
564570
// eslint-disable-next-line deprecation/deprecation
565571
return hub.withScope(() => {

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export {
3232
export {
3333
// eslint-disable-next-line deprecation/deprecation
3434
getCurrentHub,
35+
// eslint-disable-next-line deprecation/deprecation
3536
Hub,
3637
getGlobalHub,
3738
getDefaultCurrentScope,

packages/core/src/sdk.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function setCurrentClient(client: Client): void {
5555
}
5656
}
5757

58+
// eslint-disable-next-line deprecation/deprecation
5859
function isHubClass(hub: HubInterface): hub is Hub {
5960
// eslint-disable-next-line deprecation/deprecation
6061
return !!(hub as Hub).getStackTop;

packages/deno/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export {
3434
getCurrentScope,
3535
getGlobalScope,
3636
getIsolationScope,
37-
Hub,
3837
setCurrentClient,
3938
Scope,
4039
SDK_VERSION,

packages/google-cloud-serverless/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export {
1818
getCurrentScope,
1919
getGlobalScope,
2020
getIsolationScope,
21-
Hub,
2221
setCurrentClient,
2322
Scope,
2423
SDK_VERSION,

packages/node/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export {
4848
close,
4949
createTransport,
5050
flush,
51-
Hub,
5251
SDK_VERSION,
5352
getSpanStatusFromHttpCode,
5453
setHttpStatus,

packages/opentelemetry/src/asyncContextStrategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function setOpenTelemetryContextAsyncContextStrategy(): void {
4040
};
4141
}
4242

43+
// eslint-disable-next-line deprecation/deprecation
4344
function getCurrentHub(): Hub {
4445
// eslint-disable-next-line deprecation/deprecation
4546
const hub = getCurrentHubShim();

packages/remix/src/index.server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export {
2525
getCurrentScope,
2626
getGlobalScope,
2727
getIsolationScope,
28-
Hub,
2928
setCurrentClient,
3029
NodeClient,
3130
Scope,

packages/replay-internal/test/unit/session/createSession.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('Unit | session | createSession', () => {
2424
jest.spyOn(Sentry, 'getCurrentHub').mockImplementation(() => {
2525
return {
2626
captureEvent: captureEventMock,
27+
// eslint-disable-next-line deprecation/deprecation
2728
} as unknown as Hub;
2829
});
2930
});

packages/sveltekit/src/server/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export {
1818
getCurrentScope,
1919
getGlobalScope,
2020
getIsolationScope,
21-
Hub,
2221
NodeClient,
2322
setCurrentClient,
2423
Scope,

packages/types/src/hub.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ import type { User } from './user';
1212
/**
1313
* Internal class used to make sure we always have the latest internal functions
1414
* working in case we have a version conflict.
15+
*
16+
* @deprecated This interface will be removed in a future major version of the SDK in favour of
17+
* `Scope` and `Client` objects and APIs.
18+
*
19+
* Most APIs referencing `Hub` are themselves and will be removed in version 8 of the SDK. More information:
20+
* - [Migration Guide](https://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#deprecate-hub)
21+
*
1522
*/
1623
export interface Hub {
1724
/**

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export type { Event, EventHint, EventType, ErrorEvent, TransactionEvent } from '
5353
export type { EventProcessor } from './eventprocessor';
5454
export type { Exception } from './exception';
5555
export type { Extra, Extras } from './extra';
56+
// eslint-disable-next-line deprecation/deprecation
5657
export type { Hub } from './hub';
5758
export type { Integration, IntegrationClass, IntegrationFn } from './integration';
5859
export type { Mechanism } from './mechanism';

packages/vercel-edge/src/async.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function setAsyncLocalStorageAsyncContextStrategy(): void {
5151
};
5252
}
5353

54+
// eslint-disable-next-line deprecation/deprecation
5455
function getCurrentHub(): Hub {
5556
// eslint-disable-next-line deprecation/deprecation
5657
const hub = getCurrentHubShim();

packages/vercel-edge/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export {
3434
getCurrentScope,
3535
getGlobalScope,
3636
getIsolationScope,
37-
Hub,
3837
setCurrentClient,
3938
Scope,
4039
SDK_VERSION,

0 commit comments

Comments
 (0)