Skip to content

Commit 90b45f0

Browse files
lforstmydea
andauthored
feat(core): Deprecate the Hub constructor (#10574)
Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
1 parent 5a2b676 commit 90b45f0

File tree

21 files changed

+140
-5
lines changed

21 files changed

+140
-5
lines changed

MIGRATION.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,45 @@ If you are using the `Hub` right now, see the following table on how to migrate
289289
| endSession() | `Sentry.endSession()` |
290290
| shouldSendDefaultPii() | REMOVED - The closest equivalent is `Sentry.getClient().getOptions().sendDefaultPii` |
291291

292+
The `Hub` constructor is also deprecated and will be removed in the next major version. If you are creating Hubs for
293+
multi-client use like so:
294+
295+
```ts
296+
// OLD
297+
const hub = new Hub();
298+
hub.bindClient(client);
299+
makeMain(hub);
300+
```
301+
302+
instead initialize the client as follows:
303+
304+
```ts
305+
// NEW
306+
Sentry.withIsolationScope(() => {
307+
Sentry.setCurrentClient(client);
308+
client.init();
309+
});
310+
```
311+
312+
If you are using the Hub to capture events like so:
313+
314+
```ts
315+
// OLD
316+
const client = new Client();
317+
const hub = new Hub(client);
318+
hub.captureException();
319+
```
320+
321+
instead capture isolated events as follows:
322+
323+
```ts
324+
// NEW
325+
const client = new Client();
326+
const scope = new Scope();
327+
scope.setClient(client);
328+
scope.captureException();
329+
```
330+
292331
## Deprecate `client.setupIntegrations()`
293332

294333
Instead, use the new `client.init()` method. You should probably not use this directly and instead use `Sentry.init()`,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Bun Serve Integration', () => {
1919
beforeEach(() => {
2020
const options = getDefaultBunClientOptions({ tracesSampleRate: 1, debug: true });
2121
client = new BunClient(options);
22+
// eslint-disable-next-line deprecation/deprecation
2223
hub = new Hub(client);
2324
// eslint-disable-next-line deprecation/deprecation
2425
makeMain(hub);

packages/core/src/hub.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function createHub(...options: ConstructorParameters<typeof Hub>): Hub {
110110
return sentry.createHub(...options);
111111
}
112112

113+
// eslint-disable-next-line deprecation/deprecation
113114
return new Hub(...options);
114115
}
115116

@@ -132,6 +133,46 @@ export class Hub implements HubInterface {
132133
* @param client bound to the hub.
133134
* @param scope bound to the hub.
134135
* @param version number, higher number means higher priority.
136+
*
137+
* @deprecated Instantiation of Hub objects is deprecated and the constructor will be removed in version 8 of the SDK.
138+
*
139+
* If you are currently using the Hub for multi-client use like so:
140+
*
141+
* ```
142+
* // OLD
143+
* const hub = new Hub();
144+
* hub.bindClient(client);
145+
* makeMain(hub)
146+
* ```
147+
*
148+
* instead initialize the client as follows:
149+
*
150+
* ```
151+
* // NEW
152+
* Sentry.withIsolationScope(() => {
153+
* Sentry.setCurrentClient(client);
154+
* client.init();
155+
* });
156+
* ```
157+
*
158+
* If you are using the Hub to capture events like so:
159+
*
160+
* ```
161+
* // OLD
162+
* const client = new Client();
163+
* const hub = new Hub(client);
164+
* hub.captureException()
165+
* ```
166+
*
167+
* instead capture isolated events as follows:
168+
*
169+
* ```
170+
* // NEW
171+
* const client = new Client();
172+
* const scope = new Scope();
173+
* scope.setClient(client);
174+
* scope.captureException();
175+
* ```
135176
*/
136177
public constructor(
137178
client?: Client,

packages/core/test/lib/base.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe('BaseClient', () => {
119119
const options = getDefaultTestClientOptions({});
120120
const client = new TestClient(options);
121121
const scope = new Scope();
122+
// eslint-disable-next-line deprecation/deprecation
122123
const hub = new Hub(client, scope);
123124

124125
scope.addBreadcrumb({ message: 'hello' }, 100);
@@ -134,6 +135,7 @@ describe('BaseClient', () => {
134135
const options = getDefaultTestClientOptions({});
135136
const client = new TestClient(options);
136137
const scope = new Scope();
138+
// eslint-disable-next-line deprecation/deprecation
137139
const hub = new Hub(client, scope);
138140

139141
scope.addBreadcrumb({ message: 'hello' }, 100);
@@ -149,6 +151,7 @@ describe('BaseClient', () => {
149151
const options = getDefaultTestClientOptions({ maxBreadcrumbs: 1 });
150152
const client = new TestClient(options);
151153
const scope = new Scope();
154+
// eslint-disable-next-line deprecation/deprecation
152155
const hub = new Hub(client, scope);
153156

154157
scope.addBreadcrumb({ message: 'hello' }, 100);
@@ -165,6 +168,7 @@ describe('BaseClient', () => {
165168
const options = getDefaultTestClientOptions({});
166169
const client = new TestClient(options);
167170
const scope = new Scope();
171+
// eslint-disable-next-line deprecation/deprecation
168172
const hub = new Hub(client, scope);
169173

170174
scope.addBreadcrumb({ message: 'hello' });
@@ -181,6 +185,7 @@ describe('BaseClient', () => {
181185
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
182186
const client = new TestClient(options);
183187
const scope = new Scope();
188+
// eslint-disable-next-line deprecation/deprecation
184189
const hub = new Hub(client, scope);
185190

186191
// eslint-disable-next-line deprecation/deprecation
@@ -196,6 +201,7 @@ describe('BaseClient', () => {
196201
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
197202
const client = new TestClient(options);
198203
const scope = new Scope();
204+
// eslint-disable-next-line deprecation/deprecation
199205
const hub = new Hub(client, scope);
200206

201207
// eslint-disable-next-line deprecation/deprecation
@@ -211,6 +217,7 @@ describe('BaseClient', () => {
211217
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
212218
const client = new TestClient(options);
213219
const scope = new Scope();
220+
// eslint-disable-next-line deprecation/deprecation
214221
const hub = new Hub(client, scope);
215222

216223
// eslint-disable-next-line deprecation/deprecation
@@ -226,6 +233,7 @@ describe('BaseClient', () => {
226233
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
227234
const client = new TestClient(options);
228235
const scope = new Scope();
236+
// eslint-disable-next-line deprecation/deprecation
229237
const hub = new Hub(client, scope);
230238

231239
// eslint-disable-next-line deprecation/deprecation
@@ -620,6 +628,7 @@ describe('BaseClient', () => {
620628
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, maxBreadcrumbs: 1 });
621629
const client = new TestClient(options);
622630
const scope = new Scope();
631+
// eslint-disable-next-line deprecation/deprecation
623632
const hub = new Hub(client, scope);
624633
// eslint-disable-next-line deprecation/deprecation
625634
hub.addBreadcrumb({ message: '1' });

packages/core/test/lib/integration.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ describe('addIntegration', () => {
617617
}
618618

619619
const client = getTestClient();
620+
// eslint-disable-next-line deprecation/deprecation
620621
const hub = new Hub(client);
621622
// eslint-disable-next-line deprecation/deprecation
622623
makeMain(hub);
@@ -635,6 +636,7 @@ describe('addIntegration', () => {
635636
setupOnce = jest.fn();
636637
}
637638

639+
// eslint-disable-next-line deprecation/deprecation
638640
const hub = new Hub();
639641
// eslint-disable-next-line deprecation/deprecation
640642
makeMain(hub);
@@ -660,6 +662,7 @@ describe('addIntegration', () => {
660662
}
661663

662664
const client = getTestClient();
665+
// eslint-disable-next-line deprecation/deprecation
663666
const hub = new Hub(client);
664667
// eslint-disable-next-line deprecation/deprecation
665668
makeMain(hub);
@@ -683,6 +686,7 @@ describe('addIntegration', () => {
683686
}
684687

685688
const client = getTestClient();
689+
// eslint-disable-next-line deprecation/deprecation
686690
const hub = new Hub(client);
687691
// eslint-disable-next-line deprecation/deprecation
688692
makeMain(hub);

packages/core/test/lib/scope.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ describe('withActiveSpan()', () => {
522522
const options = getDefaultTestClientOptions({ enableTracing: true });
523523
const client = new TestClient(options);
524524
const scope = new Scope();
525+
// eslint-disable-next-line deprecation/deprecation
525526
const hub = new Hub(client, scope);
526527
makeMain(hub); // eslint-disable-line deprecation/deprecation
527528
});

packages/core/test/lib/sdk.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ describe('SDK', () => {
8787

8888
describe('captureCheckIn', () => {
8989
afterEach(function () {
90+
// eslint-disable-next-line deprecation/deprecation
9091
const hub = new Hub();
9192
// eslint-disable-next-line deprecation/deprecation
9293
makeMain(hub);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
99
beforeEach(() => {
1010
const options = getDefaultTestClientOptions({ tracesSampleRate: 1.0, release: '1.0.1' });
1111
const client = new TestClient(options);
12+
// eslint-disable-next-line deprecation/deprecation
1213
hub = new Hub(client);
1314
// eslint-disable-next-line deprecation/deprecation
1415
makeMain(hub);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('registerErrorHandlers()', () => {
3434
mockAddGlobalErrorInstrumentationHandler.mockClear();
3535
mockAddGlobalUnhandledRejectionInstrumentationHandler.mockClear();
3636
const options = getDefaultBrowserClientOptions({ enableTracing: true });
37+
// eslint-disable-next-line deprecation/deprecation
3738
const hub = new Hub(new BrowserClient(options));
3839
// eslint-disable-next-line deprecation/deprecation
3940
makeMain(hub);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('startSpan', () => {
3636
beforeEach(() => {
3737
const options = getDefaultTestClientOptions({ tracesSampleRate: 0.0 });
3838
client = new TestClient(options);
39+
// eslint-disable-next-line deprecation/deprecation
3940
hub = new Hub(client);
4041
// eslint-disable-next-line deprecation/deprecation
4142
makeMain(hub);
@@ -427,6 +428,7 @@ describe('startSpanManual', () => {
427428
beforeEach(() => {
428429
const options = getDefaultTestClientOptions({ tracesSampleRate: 1 });
429430
client = new TestClient(options);
431+
// eslint-disable-next-line deprecation/deprecation
430432
hub = new Hub(client);
431433
// eslint-disable-next-line deprecation/deprecation
432434
makeMain(hub);
@@ -537,6 +539,7 @@ describe('startInactiveSpan', () => {
537539
beforeEach(() => {
538540
const options = getDefaultTestClientOptions({ tracesSampleRate: 1 });
539541
client = new TestClient(options);
542+
// eslint-disable-next-line deprecation/deprecation
540543
hub = new Hub(client);
541544
// eslint-disable-next-line deprecation/deprecation
542545
makeMain(hub);
@@ -662,6 +665,7 @@ describe('continueTrace', () => {
662665
beforeEach(() => {
663666
const options = getDefaultTestClientOptions({ tracesSampleRate: 0.0 });
664667
client = new TestClient(options);
668+
// eslint-disable-next-line deprecation/deprecation
665669
hub = new Hub(client);
666670
// eslint-disable-next-line deprecation/deprecation
667671
makeMain(hub);

packages/deno/test/__snapshots__/mod.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ snapshot[`captureException 1`] = `
8282
filename: "app:///test/mod.test.ts",
8383
function: "<anonymous>",
8484
in_app: true,
85-
lineno: 46,
85+
lineno: 47,
8686
post_context: [
8787
"",
8888
" await delay(200);",
@@ -108,7 +108,7 @@ snapshot[`captureException 1`] = `
108108
filename: "app:///test/mod.test.ts",
109109
function: "something",
110110
in_app: true,
111-
lineno: 43,
111+
lineno: 44,
112112
post_context: [
113113
" }",
114114
"",

packages/deno/test/mod.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function getTestClient(
2222
});
2323

2424
const scope = new Scope();
25+
// eslint-disable-next-line deprecation/deprecation
2526
const hub = new Hub(client, scope);
2627

2728
return [hub, client];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function getCurrentHub(): Hub {
138138
*/
139139
export function makeMain(hub: Hub): Hub {
140140
// eslint-disable-next-line no-console
141-
console.warn('makeMain is a noop in @sentry/node-experimental. Use `setCurrentScope` instead.');
141+
console.warn('makeMain is a noop in @sentry/node-experimental. Use `setCurrentClient` instead.');
142142
return hub;
143143
}
144144

0 commit comments

Comments
 (0)