Skip to content

Commit 21a88a4

Browse files
committed
feat(core): Deprecate Hub class
1 parent 9bfadb5 commit 21a88a4

File tree

37 files changed

+89
-8
lines changed

37 files changed

+89
-8
lines changed

packages/browser/src/exports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export {
4242
getClient,
4343
isInitialized,
4444
getCurrentScope,
45+
// eslint-disable-next-line deprecation/deprecation
4546
Hub,
4647
// eslint-disable-next-line deprecation/deprecation
4748
lastEventId,

packages/bun/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export {
4949
getCurrentScope,
5050
getGlobalScope,
5151
getIsolationScope,
52+
// eslint-disable-next-line deprecation/deprecation
5253
Hub,
5354
// eslint-disable-next-line deprecation/deprecation
5455
lastEventId,

packages/bun/test/integrations/bunserver.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getDefaultBunClientOptions } from '../helpers';
99
const DEFAULT_PORT = 22114;
1010

1111
describe('Bun Serve Integration', () => {
12+
// eslint-disable-next-line deprecation/deprecation
1213
let hub: Hub;
1314
let client: BunClient;
1415

packages/core/src/exports.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function captureEvent(event: Event, hint?: EventHint): string {
8787
*
8888
* @deprecated Use getCurrentScope() directly.
8989
*/
90+
// eslint-disable-next-line deprecation/deprecation
9091
export function configureScope(callback: (scope: Scope) => void): ReturnType<Hub['configureScope']> {
9192
// eslint-disable-next-line deprecation/deprecation
9293
getCurrentHub().configureScope(callback);
@@ -100,6 +101,7 @@ export function configureScope(callback: (scope: Scope) => void): ReturnType<Hub
100101
*
101102
* @param breadcrumb The breadcrumb to record.
102103
*/
104+
// eslint-disable-next-line deprecation/deprecation
103105
export function addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): ReturnType<Hub['addBreadcrumb']> {
104106
// eslint-disable-next-line deprecation/deprecation
105107
getCurrentHub().addBreadcrumb(breadcrumb, hint);
@@ -110,7 +112,7 @@ export function addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): Re
110112
* @param name of the context
111113
* @param context Any kind of data. This data will be normalized.
112114
*/
113-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
115+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, deprecation/deprecation
114116
export function setContext(name: string, context: { [key: string]: any } | null): ReturnType<Hub['setContext']> {
115117
// eslint-disable-next-line deprecation/deprecation
116118
getCurrentHub().setContext(name, context);
@@ -120,6 +122,7 @@ export function setContext(name: string, context: { [key: string]: any } | null)
120122
* Set an object that will be merged sent as extra data with the event.
121123
* @param extras Extras object to merge into current context.
122124
*/
125+
// eslint-disable-next-line deprecation/deprecation
123126
export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
124127
// eslint-disable-next-line deprecation/deprecation
125128
getCurrentHub().setExtras(extras);
@@ -130,6 +133,7 @@ export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
130133
* @param key String of extra
131134
* @param extra Any kind of data. This data will be normalized.
132135
*/
136+
// eslint-disable-next-line deprecation/deprecation
133137
export function setExtra(key: string, extra: Extra): ReturnType<Hub['setExtra']> {
134138
// eslint-disable-next-line deprecation/deprecation
135139
getCurrentHub().setExtra(key, extra);
@@ -139,6 +143,7 @@ export function setExtra(key: string, extra: Extra): ReturnType<Hub['setExtra']>
139143
* Set an object that will be merged sent as tags data with the event.
140144
* @param tags Tags context object to merge into current context.
141145
*/
146+
// eslint-disable-next-line deprecation/deprecation
142147
export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['setTags']> {
143148
// eslint-disable-next-line deprecation/deprecation
144149
getCurrentHub().setTags(tags);
@@ -152,6 +157,7 @@ export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['set
152157
* @param key String key of tag
153158
* @param value Value of tag
154159
*/
160+
// eslint-disable-next-line deprecation/deprecation
155161
export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']> {
156162
// eslint-disable-next-line deprecation/deprecation
157163
getCurrentHub().setTag(key, value);
@@ -162,6 +168,7 @@ export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']>
162168
*
163169
* @param user User context object to be set in the current context. Pass `null` to unset the user.
164170
*/
171+
// eslint-disable-next-line deprecation/deprecation
165172
export function setUser(user: User | null): ReturnType<Hub['setUser']> {
166173
// eslint-disable-next-line deprecation/deprecation
167174
getCurrentHub().setUser(user);
@@ -272,6 +279,7 @@ export function withActiveSpan<T>(span: Span, callback: (scope: Scope) => T): T
272279
export function startTransaction(
273280
context: TransactionContext,
274281
customSamplingContext?: CustomSamplingContext,
282+
// eslint-disable-next-line deprecation/deprecation
275283
): ReturnType<Hub['startTransaction']> {
276284
// eslint-disable-next-line deprecation/deprecation
277285
return getCurrentHub().startTransaction({ ...context }, customSamplingContext);

packages/core/src/hub.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface AsyncContextStrategy {
6666
/**
6767
* Gets the current async context. Returns undefined if there is no current async context.
6868
*/
69+
// eslint-disable-next-line deprecation/deprecation
6970
getCurrentHub: () => Hub | undefined;
7071
/**
7172
* Runs the supplied callback in its own async context.
@@ -88,6 +89,7 @@ export interface Layer {
8889
*/
8990
export interface Carrier {
9091
__SENTRY__?: {
92+
// eslint-disable-next-line deprecation/deprecation
9193
hub?: Hub;
9294
acs?: AsyncContextStrategy;
9395
/**
@@ -103,7 +105,15 @@ export interface Carrier {
103105
}
104106

105107
/**
106-
* @inheritDoc
108+
* @deprecated The `Hub` class will be removed in version 8 of the SDK in favour of `Scope` and `Client` objects.
109+
*
110+
* If you previously used the `Hub` class directly, replace it with `Scope` and `Client` objects. More information:
111+
* - [Multiple Sentry Instances](https://docs.sentry.io/platforms/javascript/best-practices/multiple-sentry-instances/)
112+
* - [Browser Extensions](https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/)
113+
*
114+
* Some of our APIs are typed with the Hub class instead of the interface (e.g. `getCurrentHub`). Most of them are deprecated
115+
* themselves and will also be removed in version 8. More information:
116+
* - [Migration Guide](https://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#deprecate-hub)
107117
*/
108118
export class Hub implements HubInterface {
109119
/** Is a {@link Layer}[] containing the client and scope */
@@ -531,6 +541,7 @@ export class Hub implements HubInterface {
531541
/**
532542
* @inheritDoc
533543
*/
544+
// eslint-disable-next-line deprecation/deprecation
534545
public run(callback: (hub: Hub) => void): void {
535546
// eslint-disable-next-line deprecation/deprecation
536547
const oldHub = makeMain(this);
@@ -739,6 +750,7 @@ export function getMainCarrier(): Carrier {
739750
*
740751
* @deprecated Use `setCurrentClient()` instead.
741752
*/
753+
// eslint-disable-next-line deprecation/deprecation
742754
export function makeMain(hub: Hub): Hub {
743755
const registry = getMainCarrier();
744756
const oldHub = getHubFromCarrier(registry);
@@ -755,6 +767,7 @@ export function makeMain(hub: Hub): Hub {
755767
*
756768
* @deprecated Use the respective replacement method directly instead.
757769
*/
770+
// eslint-disable-next-line deprecation/deprecation
758771
export function getCurrentHub(): Hub {
759772
// Get main carrier (global for every environment)
760773
const registry = getMainCarrier();
@@ -781,6 +794,7 @@ export function getIsolationScope(): Scope {
781794
return getCurrentHub().getIsolationScope();
782795
}
783796

797+
// eslint-disable-next-line deprecation/deprecation
784798
function getGlobalHub(registry: Carrier = getMainCarrier()): Hub {
785799
// If there's no hub, or its an old API, assign a new one
786800

@@ -802,6 +816,7 @@ function getGlobalHub(registry: Carrier = getMainCarrier()): Hub {
802816
*
803817
* If the carrier does not contain a hub, a new hub is created with the global hub client and scope.
804818
*/
819+
// eslint-disable-next-line deprecation/deprecation
805820
export function ensureHubOnCarrier(carrier: Carrier, parent: Hub = getGlobalHub()): void {
806821
// If there's no hub on current domain, or it's an old API, assign a new one
807822
if (
@@ -864,6 +879,7 @@ function hasHubOnCarrier(carrier: Carrier): boolean {
864879
* @param carrier object
865880
* @hidden
866881
*/
882+
// eslint-disable-next-line deprecation/deprecation
867883
export function getHubFromCarrier(carrier: Carrier): Hub {
868884
// eslint-disable-next-line deprecation/deprecation
869885
return getGlobalSingleton<Hub>('hub', () => new Hub(), carrier);
@@ -875,6 +891,7 @@ export function getHubFromCarrier(carrier: Carrier): Hub {
875891
* @param hub Hub
876892
* @returns A boolean indicating success or failure
877893
*/
894+
// eslint-disable-next-line deprecation/deprecation
878895
export function setHubOnCarrier(carrier: Carrier, hub: Hub): boolean {
879896
if (!carrier) return false;
880897
const __SENTRY__ = (carrier.__SENTRY__ = carrier.__SENTRY__ || {});

packages/core/src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export {
4444
getCurrentHub,
4545
getIsolationScope,
4646
getHubFromCarrier,
47+
// eslint-disable-next-line deprecation/deprecation
4748
Hub,
4849
// eslint-disable-next-line deprecation/deprecation
4950
makeMain,
@@ -84,12 +85,7 @@ export { hasTracingEnabled } from './utils/hasTracingEnabled';
8485
export { isSentryRequestUrl } from './utils/isSentryRequestUrl';
8586
export { handleCallbackErrors } from './utils/handleCallbackErrors';
8687
export { parameterize } from './utils/parameterize';
87-
export {
88-
spanToTraceHeader,
89-
spanToJSON,
90-
spanIsSampled,
91-
spanToTraceContext,
92-
} from './utils/spanUtils';
88+
export { spanToTraceHeader, spanToJSON, spanIsSampled, spanToTraceContext } from './utils/spanUtils';
9389
export { getRootSpan } from './utils/getRootSpan';
9490
export { applySdkMetadata } from './utils/sdkMetadata';
9591
export { DEFAULT_ENVIRONMENT } from './constants';

packages/core/src/tracing/hubextensions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { sampleTransaction } from './sampling';
1111
import { Transaction } from './transaction';
1212

1313
/** Returns all trace headers that are currently on the top scope. */
14+
// eslint-disable-next-line deprecation/deprecation
1415
function traceHeaders(this: Hub): { [key: string]: string } {
1516
// eslint-disable-next-line deprecation/deprecation
1617
const scope = this.getScope();
@@ -40,6 +41,7 @@ function traceHeaders(this: Hub): { [key: string]: string } {
4041
* @see {@link Hub.startTransaction}
4142
*/
4243
function _startTransaction(
44+
// eslint-disable-next-line deprecation/deprecation
4345
this: Hub,
4446
transactionContext: TransactionContext,
4547
customSamplingContext?: CustomSamplingContext,
@@ -88,6 +90,7 @@ The transaction will not be sampled. Please use the ${configInstrumenter} instru
8890
* Create new idle transaction.
8991
*/
9092
export function startIdleTransaction(
93+
// eslint-disable-next-line deprecation/deprecation
9194
hub: Hub,
9295
transactionContext: TransactionContext,
9396
idleTimeout: number,

packages/core/src/tracing/idletransaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class IdleTransaction extends Transaction {
102102
*/
103103
public constructor(
104104
transactionContext: TransactionContext,
105+
// eslint-disable-next-line deprecation/deprecation
105106
private readonly _idleHub: Hub,
106107
/**
107108
* The time to wait in ms until the idle transaction will be finished. This timer is started each time

packages/core/src/tracing/trace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ export const continueTrace: ContinueTrace = <V>(
330330
};
331331

332332
function createChildSpanOrTransaction(
333+
// eslint-disable-next-line deprecation/deprecation
333334
hub: Hub,
334335
{
335336
parentSpan,

packages/core/src/tracing/transaction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
2626
/**
2727
* The reference to the current hub.
2828
*/
29+
// eslint-disable-next-line deprecation/deprecation
2930
public _hub: Hub;
3031

3132
protected _name: string;
@@ -48,6 +49,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
4849
*
4950
* @deprecated Transactions will be removed in v8. Use spans instead.
5051
*/
52+
// eslint-disable-next-line deprecation/deprecation
5153
public constructor(transactionContext: TransactionContext, hub?: Hub) {
5254
super(transactionContext);
5355
this._contexts = {};
@@ -250,6 +252,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
250252
*
251253
* @internal
252254
*/
255+
// eslint-disable-next-line deprecation/deprecation
253256
public setHub(hub: Hub): void {
254257
this._hub = hub;
255258
}

packages/core/src/tracing/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getCurrentHub } from '../hub';
99
*
1010
* @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead.
1111
*/
12+
// eslint-disable-next-line deprecation/deprecation
1213
export function getActiveTransaction<T extends Transaction>(maybeHub?: Hub): T | undefined {
1314
// eslint-disable-next-line deprecation/deprecation
1415
const hub = maybeHub || getCurrentHub();

packages/core/test/lib/tracing/dynamicSamplingContext.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { addTracingExtensions } from '../../../src/tracing';
55
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';
66

77
describe('getDynamicSamplingContextFromSpan', () => {
8+
// eslint-disable-next-line deprecation/deprecation
89
let hub: Hub;
910
beforeEach(() => {
1011
const options = getDefaultTestClientOptions({ tracesSampleRate: 1.0, release: '1.0.1' });

packages/core/test/lib/tracing/trace.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const enum Type {
2929
Async = 'async',
3030
}
3131

32+
// eslint-disable-next-line deprecation/deprecation
3233
let hub: Hub;
3334
let client: TestClient;
3435

packages/hub/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
/**
3232
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8
3333
*/
34+
// eslint-disable-next-line deprecation/deprecation
3435
export class Hub extends HubCore {}
3536

3637
/**

packages/node-experimental/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export {
7575
// eslint-disable-next-line deprecation/deprecation
7676
extractTraceparentData,
7777
flush,
78+
// eslint-disable-next-line deprecation/deprecation
7879
Hub,
7980
runWithAsyncContext,
8081
SDK_VERSION,

packages/node/src/async/domain.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function getActiveDomain<T>(): T | undefined {
77
return (domain as any).active as T | undefined;
88
}
99

10+
// eslint-disable-next-line deprecation/deprecation
1011
function getCurrentHub(): Hub | undefined {
1112
const activeDomain = getActiveDomain<Carrier>();
1213

@@ -20,6 +21,7 @@ function getCurrentHub(): Hub | undefined {
2021
return getHubFromCarrier(activeDomain);
2122
}
2223

24+
// eslint-disable-next-line deprecation/deprecation
2325
function createNewHub(parent: Hub | undefined): Hub {
2426
const carrier: Carrier = {};
2527
ensureHubOnCarrier(carrier, parent);

packages/node/src/async/hooks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ type AsyncLocalStorageConstructor = { new <T>(): AsyncLocalStorage<T> };
1212
// AsyncLocalStorage only exists in async_hook after Node v12.17.0 or v13.10.0
1313
type NewerAsyncHooks = typeof async_hooks & { AsyncLocalStorage: AsyncLocalStorageConstructor };
1414

15+
// eslint-disable-next-line deprecation/deprecation
1516
let asyncStorage: AsyncLocalStorage<Hub>;
1617

1718
/**
1819
* Sets the async context strategy to use AsyncLocalStorage which requires Node v12.17.0 or v13.10.0.
1920
*/
2021
export function setHooksAsyncContextStrategy(): void {
2122
if (!asyncStorage) {
23+
// eslint-disable-next-line deprecation/deprecation
2224
asyncStorage = new (async_hooks as NewerAsyncHooks).AsyncLocalStorage<Hub>();
2325
}
2426

27+
// eslint-disable-next-line deprecation/deprecation
2528
function getCurrentHub(): Hub | undefined {
2629
return asyncStorage.getStore();
2730
}
2831

32+
// eslint-disable-next-line deprecation/deprecation
2933
function createNewHub(parent: Hub | undefined): Hub {
3034
const carrier: Carrier = {};
3135
ensureHubOnCarrier(carrier, parent);

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export {
4848
getCurrentScope,
4949
getGlobalScope,
5050
getIsolationScope,
51+
// eslint-disable-next-line deprecation/deprecation
5152
Hub,
5253
// eslint-disable-next-line deprecation/deprecation
5354
lastEventId,

packages/node/src/integrations/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export class Http implements Integration {
171171
*/
172172
public setupOnce(
173173
_addGlobalEventProcessor: (callback: EventProcessor) => void,
174+
// eslint-disable-next-line deprecation/deprecation
174175
setupOnceGetCurrentHub: () => Hub,
175176
): void {
176177
// eslint-disable-next-line deprecation/deprecation

packages/node/test/handlers.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ import { NodeClient } from '../src/client';
1717
import { errorHandler, requestHandler, tracingHandler } from '../src/handlers';
1818
import { getDefaultNodeClientOptions } from './helper/node-client-options';
1919

20+
// eslint-disable-next-line deprecation/deprecation
2021
function mockAsyncContextStrategy(getHub: () => Hub): void {
22+
// eslint-disable-next-line deprecation/deprecation
2123
function getCurrentHub(): Hub | undefined {
2224
return getHub();
2325
}
2426

27+
// eslint-disable-next-line deprecation/deprecation
2528
function runWithAsyncContext<T>(fn: (hub: Hub) => T): T {
2629
return fn(getHub());
2730
}
@@ -195,6 +198,7 @@ describe('tracingHandler', () => {
195198

196199
const sentryTracingMiddleware = tracingHandler();
197200

201+
// eslint-disable-next-line deprecation/deprecation
198202
let hub: Hub, req: http.IncomingMessage, res: http.ServerResponse, next: () => undefined;
199203

200204
function createNoOpSpy() {

packages/node/test/integrations/undici.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { conditionalTest } from '../utils';
1212

1313
const SENTRY_DSN = 'https://0@0.ingest.sentry.io/0';
1414

15+
// eslint-disable-next-line deprecation/deprecation
1516
let hub: Hub;
1617
let fetch: typeof FetchType;
1718

0 commit comments

Comments
 (0)