From 7a77f18c8752482197704fd910ecd4ba963a1d32 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 14:38:51 +0000 Subject: [PATCH 01/12] feat(core): Deprecate the `Hub` constructor --- MIGRATION.md | 39 +++++++++++++++++++++- packages/core/src/hub.ts | 40 +++++++++++++++++++++++ packages/node-experimental/src/sdk/hub.ts | 2 +- 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index f975b13c0f4d..5cb0c5f54585 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -285,6 +285,43 @@ 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. 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()`, @@ -351,7 +388,7 @@ app.get('/your-route', req => { ); }); }); -``` +```` ## Deprecate `Sentry.lastEventId()` and `hub.lastEventId()` diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index 79359657cc8b..a227d448e288 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -132,6 +132,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, diff --git a/packages/node-experimental/src/sdk/hub.ts b/packages/node-experimental/src/sdk/hub.ts index cce73a81d71f..13eb7aeb7707 100644 --- a/packages/node-experimental/src/sdk/hub.ts +++ b/packages/node-experimental/src/sdk/hub.ts @@ -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; } From 441dd5eaafd0bc39d1c6f4b4bbc343c49a77dd9c Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 14:59:17 +0000 Subject: [PATCH 02/12] deprecations --- MIGRATION.md | 3 ++- packages/bun/test/integrations/bunserver.test.ts | 1 + packages/core/src/hub.ts | 1 + packages/core/test/lib/base.test.ts | 9 +++++++++ packages/core/test/lib/exports.test.ts | 3 +++ packages/core/test/lib/integration.test.ts | 4 ++++ packages/core/test/lib/scope.test.ts | 1 + packages/core/test/lib/sdk.test.ts | 1 + .../lib/tracing/dynamicSamplingContext.test.ts | 1 + packages/core/test/lib/tracing/errors.test.ts | 1 + packages/core/test/lib/tracing/trace.test.ts | 4 ++++ packages/node/test/handlers.test.ts | 14 ++++++++++++++ packages/node/test/integrations/http.test.ts | 7 +++++++ packages/node/test/integrations/undici.test.ts | 2 ++ .../opentelemetry-node/test/propagator.test.ts | 2 +- .../opentelemetry-node/test/spanprocessor.test.ts | 4 ++++ packages/opentelemetry/test/propagator.test.ts | 1 + .../test/browser/backgroundtab.test.ts | 1 + 18 files changed, 58 insertions(+), 2 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 5cb0c5f54585..d2bd25c29e93 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -285,7 +285,8 @@ 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. If you are creating Hubs for multi-client use like so: +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 diff --git a/packages/bun/test/integrations/bunserver.test.ts b/packages/bun/test/integrations/bunserver.test.ts index bd62881b8ccf..fd55e56ff50f 100644 --- a/packages/bun/test/integrations/bunserver.test.ts +++ b/packages/bun/test/integrations/bunserver.test.ts @@ -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); diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index a227d448e288..f8f274c9e091 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -110,6 +110,7 @@ function createHub(...options: ConstructorParameters): Hub { return sentry.createHub(...options); } + // eslint-disable-next-line deprecation/deprecation return new Hub(...options); } diff --git a/packages/core/test/lib/base.test.ts b/packages/core/test/lib/base.test.ts index 197ffa189779..855ea73da056 100644 --- a/packages/core/test/lib/base.test.ts +++ b/packages/core/test/lib/base.test.ts @@ -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); @@ -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); @@ -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); @@ -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' }); @@ -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 @@ -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 @@ -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 @@ -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 @@ -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' }); diff --git a/packages/core/test/lib/exports.test.ts b/packages/core/test/lib/exports.test.ts index cb4c9fbdd16d..e611c25e42dd 100644 --- a/packages/core/test/lib/exports.test.ts +++ b/packages/core/test/lib/exports.test.ts @@ -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); @@ -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); @@ -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); diff --git a/packages/core/test/lib/integration.test.ts b/packages/core/test/lib/integration.test.ts index e819f9413aec..a86c83903152 100644 --- a/packages/core/test/lib/integration.test.ts +++ b/packages/core/test/lib/integration.test.ts @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/packages/core/test/lib/scope.test.ts b/packages/core/test/lib/scope.test.ts index 4b4242ce7dc6..88e275cc84dd 100644 --- a/packages/core/test/lib/scope.test.ts +++ b/packages/core/test/lib/scope.test.ts @@ -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 }); diff --git a/packages/core/test/lib/sdk.test.ts b/packages/core/test/lib/sdk.test.ts index c9d18c02c78e..c56bb8b11620 100644 --- a/packages/core/test/lib/sdk.test.ts +++ b/packages/core/test/lib/sdk.test.ts @@ -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); diff --git a/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts b/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts index 01c99e3b87fd..db79c8850200 100644 --- a/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts +++ b/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts @@ -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); diff --git a/packages/core/test/lib/tracing/errors.test.ts b/packages/core/test/lib/tracing/errors.test.ts index b83820865ede..35a80f60265a 100644 --- a/packages/core/test/lib/tracing/errors.test.ts +++ b/packages/core/test/lib/tracing/errors.test.ts @@ -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); diff --git a/packages/core/test/lib/tracing/trace.test.ts b/packages/core/test/lib/tracing/trace.test.ts index 4c9190e56b6a..bb5302bb54db 100644 --- a/packages/core/test/lib/tracing/trace.test.ts +++ b/packages/core/test/lib/tracing/trace.test.ts @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/packages/node/test/handlers.test.ts b/packages/node/test/handlers.test.ts index 8438a3fc2acd..34e00f06b9c6 100644 --- a/packages/node/test/handlers.test.ts +++ b/packages/node/test/handlers.test.ts @@ -66,6 +66,7 @@ describe('requestHandler', () => { it('autoSessionTracking is enabled, sets requestSession status to ok, when handling a request', () => { const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '1.2' }); client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); @@ -80,6 +81,7 @@ describe('requestHandler', () => { it('autoSessionTracking is disabled, does not set requestSession, when handling a request', () => { const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '1.2' }); client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); @@ -94,6 +96,7 @@ describe('requestHandler', () => { it('autoSessionTracking is enabled, calls _captureRequestSession, on response finish', done => { const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '1.2' }); client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); @@ -116,6 +119,7 @@ describe('requestHandler', () => { it('autoSessionTracking is disabled, does not call _captureRequestSession, on response finish', done => { const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '1.2' }); client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); @@ -162,6 +166,7 @@ describe('requestHandler', () => { }); it('stores request and request data options in `sdkProcessingMetadata`', () => { + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(new NodeClient(getDefaultNodeClientOptions())); jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); mockAsyncContextStrategy(() => hub); @@ -198,6 +203,7 @@ describe('tracingHandler', () => { } beforeEach(() => { + // eslint-disable-next-line deprecation/deprecation hub = new Hub(new NodeClient(getDefaultNodeClientOptions({ tracesSampleRate: 1.0 }))); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -322,6 +328,7 @@ describe('tracingHandler', () => { it('extracts request data for sampling context', () => { const tracesSampler = jest.fn(); const options = getDefaultNodeClientOptions({ tracesSampler }); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(new NodeClient(options)); mockAsyncContextStrategy(() => hub); @@ -344,6 +351,7 @@ describe('tracingHandler', () => { it('puts its transaction on the scope', () => { const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 }); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(new NodeClient(options)); jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); @@ -474,6 +482,7 @@ describe('tracingHandler', () => { it('stores request in transaction metadata', () => { const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 }); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(new NodeClient(options)); jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub); @@ -532,6 +541,7 @@ describe('errorHandler()', () => { client.initSessionFlusher(); const scope = getCurrentScope(); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); jest.spyOn(client, '_captureRequestSession'); @@ -548,6 +558,7 @@ describe('errorHandler()', () => { client = new NodeClient(options); const scope = getCurrentScope(); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); jest.spyOn(client, '_captureRequestSession'); @@ -566,6 +577,7 @@ describe('errorHandler()', () => { // by the`requestHandler`) client.initSessionFlusher(); const scope = new Scope(); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client, scope); mockAsyncContextStrategy(() => hub); @@ -588,6 +600,7 @@ describe('errorHandler()', () => { // by the`requestHandler`) client.initSessionFlusher(); const scope = new Scope(); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client, scope); jest.spyOn(client, '_captureRequestSession'); @@ -602,6 +615,7 @@ describe('errorHandler()', () => { const options = getDefaultNodeClientOptions({}); client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); mockAsyncContextStrategy(() => hub); // eslint-disable-next-line deprecation/deprecation diff --git a/packages/node/test/integrations/http.test.ts b/packages/node/test/integrations/http.test.ts index 527ef48c3f0f..bcc45350193f 100644 --- a/packages/node/test/integrations/http.test.ts +++ b/packages/node/test/integrations/http.test.ts @@ -67,6 +67,7 @@ describe('tracing', () => { ...customOptions, }); const client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -270,6 +271,7 @@ describe('tracing', () => { environment: 'production', instrumenter: 'otel', }); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(new NodeClient(options)); // eslint-disable-next-line deprecation/deprecation @@ -371,6 +373,7 @@ describe('tracing', () => { }); const client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -622,6 +625,7 @@ describe('default protocols', () => { }, }); const client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -709,6 +713,7 @@ describe('httpIntegration', () => { environment: 'production', }); const client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -769,6 +774,7 @@ describe('httpIntegration', () => { describe('_shouldCreateSpans', () => { beforeEach(function () { + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -790,6 +796,7 @@ describe('_shouldCreateSpans', () => { describe('_getShouldCreateSpanForRequest', () => { beforeEach(function () { + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(); // eslint-disable-next-line deprecation/deprecation makeMain(hub); diff --git a/packages/node/test/integrations/undici.test.ts b/packages/node/test/integrations/undici.test.ts index 1decb76006fd..e5aef807190f 100644 --- a/packages/node/test/integrations/undici.test.ts +++ b/packages/node/test/integrations/undici.test.ts @@ -34,6 +34,7 @@ const DEFAULT_OPTIONS = getDefaultNodeClientOptions({ beforeEach(() => { const client = new NodeClient(DEFAULT_OPTIONS); + // eslint-disable-next-line deprecation/deprecation hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -386,6 +387,7 @@ conditionalTest({ min: 16 })('Undici integration', () => { environment: 'production', }); const client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); diff --git a/packages/opentelemetry-node/test/propagator.test.ts b/packages/opentelemetry-node/test/propagator.test.ts index ddd4594c5157..01ed5eb1a9f6 100644 --- a/packages/opentelemetry-node/test/propagator.test.ts +++ b/packages/opentelemetry-node/test/propagator.test.ts @@ -46,7 +46,7 @@ describe('SentryPropagator', () => { publicKey: 'abc', }), }; - // @ts-expect-error Use mock client for unit tests + // eslint-disable-next-line deprecation/deprecation const hub: Hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); diff --git a/packages/opentelemetry-node/test/spanprocessor.test.ts b/packages/opentelemetry-node/test/spanprocessor.test.ts index 940f5c38bdab..072ba35881f8 100644 --- a/packages/opentelemetry-node/test/spanprocessor.test.ts +++ b/packages/opentelemetry-node/test/spanprocessor.test.ts @@ -46,6 +46,7 @@ describe('SentrySpanProcessor', () => { SPAN_MAP.clear(); client = new NodeClient(DEFAULT_NODE_CLIENT_OPTIONS); + // eslint-disable-next-line deprecation/deprecation hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -964,6 +965,7 @@ describe('SentrySpanProcessor', () => { return null; }, }); + // eslint-disable-next-line deprecation/deprecation hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -1011,6 +1013,7 @@ describe('SentrySpanProcessor', () => { return null; }, }); + // eslint-disable-next-line deprecation/deprecation hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); @@ -1058,6 +1061,7 @@ describe('SentrySpanProcessor', () => { sentryTransaction = transaction; }); + // eslint-disable-next-line deprecation/deprecation hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); diff --git a/packages/opentelemetry/test/propagator.test.ts b/packages/opentelemetry/test/propagator.test.ts index a4eb98ab2126..089a464399a2 100644 --- a/packages/opentelemetry/test/propagator.test.ts +++ b/packages/opentelemetry/test/propagator.test.ts @@ -41,6 +41,7 @@ describe('SentryPropagator', () => { }), }; // @ts-expect-error Use mock client for unit tests + // eslint-disable-next-line deprecation/deprecation const hub: Hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); diff --git a/packages/tracing-internal/test/browser/backgroundtab.test.ts b/packages/tracing-internal/test/browser/backgroundtab.test.ts index 38dbc04bae37..aa5889c89958 100644 --- a/packages/tracing-internal/test/browser/backgroundtab.test.ts +++ b/packages/tracing-internal/test/browser/backgroundtab.test.ts @@ -15,6 +15,7 @@ describe('registerBackgroundTabDetection', () => { global.document = dom.window.document; const options = getDefaultBrowserClientOptions({ tracesSampleRate: 1 }); + // eslint-disable-next-line deprecation/deprecation hub = new Hub(new TestClient(options)); // eslint-disable-next-line deprecation/deprecation makeMain(hub); From 8aaf552d4618f8c3406bd3a61da7a2fbcc41b77d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 16:03:38 +0100 Subject: [PATCH 03/12] Apply suggestions from code review Co-authored-by: Francesco Novy --- MIGRATION.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index d2bd25c29e93..9069ae0971b3 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -285,10 +285,10 @@ 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 +The `Hub` constructor is also deprecated and will be removed in the next major version. If you are creating Hubs for multi-client use like so: -``` +```js // OLD const hub = new Hub(); hub.bindClient(client); @@ -297,7 +297,7 @@ makeMain(hub) instead initialize the client as follows: -``` +```js // NEW Sentry.withIsolationScope(() => { Sentry.setCurrentClient(client); @@ -307,7 +307,7 @@ Sentry.withIsolationScope(() => { If you are using the Hub to capture events like so: -``` +```js // OLD const client = new Client(); const hub = new Hub(client); @@ -322,7 +322,6 @@ 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()`, From d24493aabd7251855935af83ac86b2e8cf3f0f6b Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 16:03:50 +0100 Subject: [PATCH 04/12] Update MIGRATION.md Co-authored-by: Francesco Novy --- MIGRATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MIGRATION.md b/MIGRATION.md index 9069ae0971b3..ef728dcf0e19 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -316,7 +316,7 @@ hub.captureException() instead capture isolated events as follows: -```` +```js // NEW const client = new Client(); const scope = new Scope(); From 22af519c8b1bedf580fd05631b322d185782fa13 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 15:13:36 +0000 Subject: [PATCH 05/12] lint --- MIGRATION.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 6deb0bcab759..66114f62b03d 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -289,43 +289,45 @@ 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 deprecated and will be removed in the next major version. If you are creating -Hubs for multi-client use like so: +The `Hub` constructor is also deprecated and will be removed in the next major version. If you are creating Hubs for +multi-client use like so: -```js +```ts // OLD const hub = new Hub(); hub.bindClient(client); -makeMain(hub) +makeMain(hub); ``` instead initialize the client as follows: -```js +```ts // NEW Sentry.withIsolationScope(() => { - Sentry.setCurrentClient(client); - client.init(); + Sentry.setCurrentClient(client); + client.init(); }); ``` If you are using the Hub to capture events like so: -```js +```ts // OLD const client = new Client(); const hub = new Hub(client); -hub.captureException() +hub.captureException(); ``` instead capture isolated events as follows: -```js +```ts // 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()`, @@ -392,7 +394,7 @@ app.get('/your-route', req => { ); }); }); -```` +``` ## Deprecate `Sentry.lastEventId()` and `hub.lastEventId()` From 63647f17f757711a67f0bbf40aa7b3ff33096360 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 15:14:15 +0000 Subject: [PATCH 06/12] fix --- packages/sveltekit/test/server/handle.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/sveltekit/test/server/handle.test.ts b/packages/sveltekit/test/server/handle.test.ts index 6465cbfe5da5..5498d80ea0ed 100644 --- a/packages/sveltekit/test/server/handle.test.ts +++ b/packages/sveltekit/test/server/handle.test.ts @@ -91,6 +91,7 @@ beforeAll(() => { beforeEach(() => { const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 }); client = new NodeClient(options); + // eslint-disable-next-line deprecation/deprecation hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); From 0d8efca75115645de8199e6553f9a5215eb5515d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 15:39:42 +0000 Subject: [PATCH 07/12] lint --- packages/deno/test/mod.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/deno/test/mod.test.ts b/packages/deno/test/mod.test.ts index 657ce0a1f233..aae0963b8da5 100644 --- a/packages/deno/test/mod.test.ts +++ b/packages/deno/test/mod.test.ts @@ -22,6 +22,7 @@ function getTestClient( }); const scope = new Scope(); + // eslint-disable-next-line deprecation/deprecation const hub = new Hub(client, scope); return [hub, client]; From ca8bfebfda448051c8c14ed2bb9cd6ea6752f753 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 15:51:20 +0000 Subject: [PATCH 08/12] Update deno snapshot --- packages/deno/test/__snapshots__/mod.test.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/deno/test/__snapshots__/mod.test.ts.snap b/packages/deno/test/__snapshots__/mod.test.ts.snap index 607d87b968bc..d728072d38d6 100644 --- a/packages/deno/test/__snapshots__/mod.test.ts.snap +++ b/packages/deno/test/__snapshots__/mod.test.ts.snap @@ -82,7 +82,7 @@ snapshot[`captureException 1`] = ` filename: "app:///test/mod.test.ts", function: "", in_app: true, - lineno: 46, + lineno: 47, post_context: [ "", " await delay(200);", @@ -108,7 +108,7 @@ snapshot[`captureException 1`] = ` filename: "app:///test/mod.test.ts", function: "something", in_app: true, - lineno: 43, + lineno: 44, post_context: [ " }", "", From a73bd717d68c3d15c85354536ba455ff2ea7015b Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 8 Feb 2024 15:55:16 +0000 Subject: [PATCH 09/12] ???? --- packages/opentelemetry/test/propagator.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/opentelemetry/test/propagator.test.ts b/packages/opentelemetry/test/propagator.test.ts index 089a464399a2..73d788bb4e0c 100644 --- a/packages/opentelemetry/test/propagator.test.ts +++ b/packages/opentelemetry/test/propagator.test.ts @@ -40,9 +40,8 @@ describe('SentryPropagator', () => { publicKey: 'abc', }), }; - // @ts-expect-error Use mock client for unit tests // eslint-disable-next-line deprecation/deprecation - const hub: Hub = new Hub(client); + const hub: Hub = new Hub(client as any); // eslint-disable-next-line deprecation/deprecation makeMain(hub); From 9f2ca413d5e832b2f81a710715622a3d5511b138 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 9 Feb 2024 08:34:58 +0000 Subject: [PATCH 10/12] pls --- packages/opentelemetry/test/propagator.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry/test/propagator.test.ts b/packages/opentelemetry/test/propagator.test.ts index 73d788bb4e0c..29c9bf9a37b2 100644 --- a/packages/opentelemetry/test/propagator.test.ts +++ b/packages/opentelemetry/test/propagator.test.ts @@ -41,7 +41,7 @@ describe('SentryPropagator', () => { }), }; // eslint-disable-next-line deprecation/deprecation - const hub: Hub = new Hub(client as any); + const hub = new Hub(client as any); // eslint-disable-next-line deprecation/deprecation makeMain(hub); From 04895b5776d4a488f333fc3ffdfedb2836785e85 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 9 Feb 2024 09:09:53 +0000 Subject: [PATCH 11/12] wth man --- packages/opentelemetry/test/propagator.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry/test/propagator.test.ts b/packages/opentelemetry/test/propagator.test.ts index 29c9bf9a37b2..20a9941161d2 100644 --- a/packages/opentelemetry/test/propagator.test.ts +++ b/packages/opentelemetry/test/propagator.test.ts @@ -40,7 +40,8 @@ describe('SentryPropagator', () => { publicKey: 'abc', }), }; - // eslint-disable-next-line deprecation/deprecation + // eslint-disable-next-line deprecation/deprecation, @typescript-eslint/ban-ts-comment + // @ts-ignore f this s const hub = new Hub(client as any); // eslint-disable-next-line deprecation/deprecation makeMain(hub); From 85337bd39fc6f18a055ee4916a23c305db2708db Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 9 Feb 2024 10:23:11 +0000 Subject: [PATCH 12/12] . --- packages/opentelemetry-node/test/propagator.test.ts | 3 ++- packages/opentelemetry/test/propagator.test.ts | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-node/test/propagator.test.ts b/packages/opentelemetry-node/test/propagator.test.ts index 01ed5eb1a9f6..494b3aff7f07 100644 --- a/packages/opentelemetry-node/test/propagator.test.ts +++ b/packages/opentelemetry-node/test/propagator.test.ts @@ -46,8 +46,9 @@ describe('SentryPropagator', () => { publicKey: 'abc', }), }; + // @ts-expect-error Use mock client for unit tests // eslint-disable-next-line deprecation/deprecation - const hub: Hub = new Hub(client); + const hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub); diff --git a/packages/opentelemetry/test/propagator.test.ts b/packages/opentelemetry/test/propagator.test.ts index 20a9941161d2..012542d47e35 100644 --- a/packages/opentelemetry/test/propagator.test.ts +++ b/packages/opentelemetry/test/propagator.test.ts @@ -40,9 +40,10 @@ describe('SentryPropagator', () => { publicKey: 'abc', }), }; - // eslint-disable-next-line deprecation/deprecation, @typescript-eslint/ban-ts-comment - // @ts-ignore f this s - const hub = new Hub(client as any); + + // @ts-expect-error Use mock client for unit tests + // eslint-disable-next-line deprecation/deprecation + const hub = new Hub(client); // eslint-disable-next-line deprecation/deprecation makeMain(hub);