Skip to content

feat(core): Deprecate the Hub constructor #10574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,44 @@ If you are using the `Hub` right now, see the following table on how to migrate
| endSession() | `Sentry.endSession()` |
| shouldSendDefaultPii() | REMOVED - The closest equivalent is `Sentry.getClient().getOptions().sendDefaultPii` |

The `Hub` constructor is also gonna be deprecated and will be removed in the next major version. If you are creating
Hubs for multi-client use like so:

```
// OLD
const hub = new Hub();
hub.bindClient(client);
makeMain(hub)
```

instead initialize the client as follows:

```
// NEW
Sentry.withIsolationScope(() => {
Sentry.setCurrentClient(client);
client.init();
});
```

If you are using the Hub to capture events like so:

```
// OLD
const client = new Client();
const hub = new Hub(client);
hub.captureException()
```

instead capture isolated events as follows:

````
// NEW
const client = new Client();
const scope = new Scope();
scope.setClient(client);
scope.captureException();

## Deprecate `client.setupIntegrations()`

Instead, use the new `client.init()` method. You should probably not use this directly and instead use `Sentry.init()`,
Expand Down Expand Up @@ -351,7 +389,7 @@ app.get('/your-route', req => {
);
});
});
```
````

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

Expand Down
1 change: 1 addition & 0 deletions packages/bun/test/integrations/bunserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Bun Serve Integration', () => {
beforeEach(() => {
const options = getDefaultBunClientOptions({ tracesSampleRate: 1, debug: true });
client = new BunClient(options);
// eslint-disable-next-line deprecation/deprecation
hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down
41 changes: 41 additions & 0 deletions packages/core/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function createHub(...options: ConstructorParameters<typeof Hub>): Hub {
return sentry.createHub(...options);
}

// eslint-disable-next-line deprecation/deprecation
return new Hub(...options);
}

Expand All @@ -132,6 +133,46 @@ export class Hub implements HubInterface {
* @param client bound to the hub.
* @param scope bound to the hub.
* @param version number, higher number means higher priority.
*
* @deprecated Instantiation of Hub objects is deprecated and the constructor will be removed in version 8 of the SDK.
*
* If you are currently using the Hub for multi-client use like so:
*
* ```
* // OLD
* const hub = new Hub();
* hub.bindClient(client);
* makeMain(hub)
* ```
*
* instead initialize the client as follows:
*
* ```
* // NEW
* Sentry.withIsolationScope(() => {
* Sentry.setCurrentClient(client);
* client.init();
* });
* ```
*
* If you are using the Hub to capture events like so:
*
* ```
* // OLD
* const client = new Client();
* const hub = new Hub(client);
* hub.captureException()
* ```
*
* instead capture isolated events as follows:
*
* ```
* // NEW
* const client = new Client();
* const scope = new Scope();
* scope.setClient(client);
* scope.captureException();
* ```
*/
public constructor(
client?: Client,
Expand Down
9 changes: 9 additions & 0 deletions packages/core/test/lib/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('BaseClient', () => {
const options = getDefaultTestClientOptions({});
const client = new TestClient(options);
const scope = new Scope();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client, scope);

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

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

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

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

// eslint-disable-next-line deprecation/deprecation
Expand All @@ -196,6 +201,7 @@ describe('BaseClient', () => {
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
const client = new TestClient(options);
const scope = new Scope();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client, scope);

// eslint-disable-next-line deprecation/deprecation
Expand All @@ -211,6 +217,7 @@ describe('BaseClient', () => {
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
const client = new TestClient(options);
const scope = new Scope();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client, scope);

// eslint-disable-next-line deprecation/deprecation
Expand All @@ -226,6 +233,7 @@ describe('BaseClient', () => {
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
const client = new TestClient(options);
const scope = new Scope();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client, scope);

// eslint-disable-next-line deprecation/deprecation
Expand Down Expand Up @@ -620,6 +628,7 @@ describe('BaseClient', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, maxBreadcrumbs: 1 });
const client = new TestClient(options);
const scope = new Scope();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client, scope);
// eslint-disable-next-line deprecation/deprecation
hub.addBreadcrumb({ message: '1' });
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/lib/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function getTestClient(): TestClient {
describe('withScope', () => {
beforeEach(() => {
const client = getTestClient();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down Expand Up @@ -173,6 +174,7 @@ describe('withScope', () => {
describe('session APIs', () => {
beforeEach(() => {
const client = getTestClient();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down Expand Up @@ -326,6 +328,7 @@ describe('isInitialized', () => {

it('returns true if client is setup', () => {
const client = getTestClient();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down
4 changes: 4 additions & 0 deletions packages/core/test/lib/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ describe('addIntegration', () => {
}

const client = getTestClient();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand All @@ -635,6 +636,7 @@ describe('addIntegration', () => {
setupOnce = jest.fn();
}

// eslint-disable-next-line deprecation/deprecation
const hub = new Hub();
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand All @@ -660,6 +662,7 @@ describe('addIntegration', () => {
}

const client = getTestClient();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand All @@ -683,6 +686,7 @@ describe('addIntegration', () => {
}

const client = getTestClient();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/lib/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ describe('withActiveSpan()', () => {
const options = getDefaultTestClientOptions({ enableTracing: true });
const client = new TestClient(options);
const scope = new Scope();
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(client, scope);
makeMain(hub); // eslint-disable-line deprecation/deprecation
});
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/lib/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('SDK', () => {

describe('captureCheckIn', () => {
afterEach(function () {
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub();
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
beforeEach(() => {
const options = getDefaultTestClientOptions({ tracesSampleRate: 1.0, release: '1.0.1' });
const client = new TestClient(options);
// eslint-disable-next-line deprecation/deprecation
hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/lib/tracing/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('registerErrorHandlers()', () => {
mockAddGlobalErrorInstrumentationHandler.mockClear();
mockAddGlobalUnhandledRejectionInstrumentationHandler.mockClear();
const options = getDefaultBrowserClientOptions({ enableTracing: true });
// eslint-disable-next-line deprecation/deprecation
const hub = new Hub(new BrowserClient(options));
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down
4 changes: 4 additions & 0 deletions packages/core/test/lib/tracing/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('startSpan', () => {
beforeEach(() => {
const options = getDefaultTestClientOptions({ tracesSampleRate: 0.0 });
client = new TestClient(options);
// eslint-disable-next-line deprecation/deprecation
hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down Expand Up @@ -427,6 +428,7 @@ describe('startSpanManual', () => {
beforeEach(() => {
const options = getDefaultTestClientOptions({ tracesSampleRate: 1 });
client = new TestClient(options);
// eslint-disable-next-line deprecation/deprecation
hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down Expand Up @@ -537,6 +539,7 @@ describe('startInactiveSpan', () => {
beforeEach(() => {
const options = getDefaultTestClientOptions({ tracesSampleRate: 1 });
client = new TestClient(options);
// eslint-disable-next-line deprecation/deprecation
hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down Expand Up @@ -662,6 +665,7 @@ describe('continueTrace', () => {
beforeEach(() => {
const options = getDefaultTestClientOptions({ tracesSampleRate: 0.0 });
client = new TestClient(options);
// eslint-disable-next-line deprecation/deprecation
hub = new Hub(client);
// eslint-disable-next-line deprecation/deprecation
makeMain(hub);
Expand Down
2 changes: 1 addition & 1 deletion packages/node-experimental/src/sdk/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function getCurrentHub(): Hub {
*/
export function makeMain(hub: Hub): Hub {
// eslint-disable-next-line no-console
console.warn('makeMain is a noop in @sentry/node-experimental. Use `setCurrentScope` instead.');
console.warn('makeMain is a noop in @sentry/node-experimental. Use `setCurrentClient` instead.');
return hub;
}

Expand Down
Loading