Skip to content

Commit 7a77f18

Browse files
author
Luca Forstner
committed
feat(core): Deprecate the Hub constructor
1 parent a985487 commit 7a77f18

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

MIGRATION.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,43 @@ If you are using the `Hub` right now, see the following table on how to migrate
285285
| endSession() | `Sentry.endSession()` |
286286
| shouldSendDefaultPii() | REMOVED - The closest equivalent is `Sentry.getClient().getOptions().sendDefaultPii` |
287287

288+
The `Hub` constructor is also gonna be deprecated. If you are creating Hubs for multi-client use like so:
289+
290+
```
291+
// OLD
292+
const hub = new Hub();
293+
hub.bindClient(client);
294+
makeMain(hub)
295+
```
296+
297+
instead initialize the client as follows:
298+
299+
```
300+
// NEW
301+
Sentry.withIsolationScope(() => {
302+
Sentry.setCurrentClient(client);
303+
client.init();
304+
});
305+
```
306+
307+
If you are using the Hub to capture events like so:
308+
309+
```
310+
// OLD
311+
const client = new Client();
312+
const hub = new Hub(client);
313+
hub.captureException()
314+
```
315+
316+
instead capture isolated events as follows:
317+
318+
````
319+
// NEW
320+
const client = new Client();
321+
const scope = new Scope();
322+
scope.setClient(client);
323+
scope.captureException();
324+
288325
## Deprecate `client.setupIntegrations()`
289326
290327
Instead, use the new `client.init()` method. You should probably not use this directly and instead use `Sentry.init()`,
@@ -351,7 +388,7 @@ app.get('/your-route', req => {
351388
);
352389
});
353390
});
354-
```
391+
````
355392

356393
## Deprecate `Sentry.lastEventId()` and `hub.lastEventId()`
357394

packages/core/src/hub.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,46 @@ export class Hub implements HubInterface {
132132
* @param client bound to the hub.
133133
* @param scope bound to the hub.
134134
* @param version number, higher number means higher priority.
135+
*
136+
* @deprecated Instantiation of Hub objects is deprecated and the constructor will be removed in version 8 of the SDK.
137+
*
138+
* If you are currently using the Hub for multi-client use like so:
139+
*
140+
* ```
141+
* // OLD
142+
* const hub = new Hub();
143+
* hub.bindClient(client);
144+
* makeMain(hub)
145+
* ```
146+
*
147+
* instead initialize the client as follows:
148+
*
149+
* ```
150+
* // NEW
151+
* Sentry.withIsolationScope(() => {
152+
* Sentry.setCurrentClient(client);
153+
* client.init();
154+
* });
155+
* ```
156+
*
157+
* If you are using the Hub to capture events like so:
158+
*
159+
* ```
160+
* // OLD
161+
* const client = new Client();
162+
* const hub = new Hub(client);
163+
* hub.captureException()
164+
* ```
165+
*
166+
* instead capture isolated events as follows:
167+
*
168+
* ```
169+
* // NEW
170+
* const client = new Client();
171+
* const scope = new Scope();
172+
* scope.setClient(client);
173+
* scope.captureException();
174+
* ```
135175
*/
136176
public constructor(
137177
client?: 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)