Skip to content

Commit 9d861fe

Browse files
authored
feat(v7/core): Deprecate Hub class (#11528)
Deprecate the `Hub` class which we'll remove in a follow-up PR in v8. The replacement is to mostly use the scope-centered APIs. Most APIs that relied on the `Hub` class (unfortunately quite a lot - looks like we weren't really consistent in using the Hub interface instead of the class) are already deprecated and already removed in v8.
1 parent ad2685a commit 9d861fe

File tree

48 files changed

+119
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+119
-22
lines changed

packages/astro/src/index.server.ts

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

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,

0 commit comments

Comments
 (0)