From 1339043d07b6e739283e6c81b84e99de418b3ffb Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 16 Jan 2024 15:39:56 +0100 Subject: [PATCH] feat(core): Deprecate `getCurrentHub()` Instead, users should use the direct replacement of the hub method. --- MIGRATION.md | 10 ++++++++- packages/astro/src/index.server.ts | 1 + packages/browser/src/exports.ts | 1 + packages/browser/src/sdk.ts | 1 + .../test/unit/profiling/hubextensions.test.ts | 6 ++---- packages/bun/src/index.ts | 1 + packages/core/src/exports.ts | 8 ++++--- packages/core/src/hub.ts | 2 ++ packages/core/src/index.ts | 1 + packages/core/src/sdk.ts | 6 +++--- packages/core/src/tracing/trace.ts | 4 ++++ packages/core/src/tracing/transaction.ts | 1 + packages/core/src/tracing/utils.ts | 1 + packages/core/test/lib/async-context.test.ts | 2 ++ packages/core/test/lib/sdk.test.ts | 21 ++++++++++--------- packages/deno/src/index.ts | 1 + packages/hub/src/index.ts | 1 + packages/nextjs/test/serverSdk.test.ts | 3 +++ packages/node/src/index.ts | 1 + packages/node/test/async/domain.test.ts | 1 + packages/node/test/async/hooks.test.ts | 1 + packages/node/test/index.test.ts | 1 + .../opentelemetry-node/src/spanprocessor.ts | 3 ++- packages/react/src/profiler.tsx | 5 ++++- packages/remix/src/index.server.ts | 1 + packages/remix/src/utils/instrumentServer.ts | 1 + .../remix/src/utils/serverAdapters/express.ts | 1 + .../test/unit/session/createSession.test.ts | 10 +++++---- packages/serverless/src/index.ts | 1 + packages/sveltekit/src/server/index.ts | 1 + .../src/node/integrations/prisma.ts | 1 + packages/tracing/test/index.test.ts | 1 + packages/vercel-edge/src/index.ts | 1 + packages/vue/src/integration.ts | 9 ++++---- .../test/integration/VueIntegration.test.ts | 4 ++-- packages/vue/test/integration/init.test.ts | 2 +- 36 files changed, 81 insertions(+), 35 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index bf4a7683e40f..49be1f12de03 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -10,6 +10,14 @@ npx @sentry/migr8@latest This will let you select which updates to run, and automatically update your code. Make sure to still review all code changes! +## Deprecate `getCurrentHub()` + +In v8, you will no longer have a Hub, only Scopes as a concept. This also means that `getCurrentHub()` will eventually +be removed. + +Instead of `getCurrentHub()`, use the respective replacement API directly - see [Deprecate Hub](#deprecate-hub) for +details. + ## Deprecate `hub.bindClient()` and `makeMain()` Instead, either directly use `initAndBind()`, or the new APIs `setCurrentClient()` and `client.init()`. See @@ -54,7 +62,7 @@ If you are using the `Hub` right now, see the following table on how to migrate | ---------------------- | ------------------------------------------------------------------------------------ | | `new Hub()` | `withScope()`, `withIsolationScope()` or `new Scope()` | | hub.isOlderThan() | REMOVED - Was used to compare `Hub` instances, which are gonna be removed | -| hub.bindClient() | A combination of `scope.setClient()` and `client.setupIntegrations()` | +| hub.bindClient() | A combination of `scope.setClient()` and `client.init()` | | hub.pushScope() | `Sentry.withScope()` | | hub.popScope() | `Sentry.withScope()` | | hub.withScope() | `Sentry.withScope()` | diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index 4358fa6ab4ea..f2136c859a28 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -25,6 +25,7 @@ export { // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, getCurrentScope, diff --git a/packages/browser/src/exports.ts b/packages/browser/src/exports.ts index 116f06719fee..6a7e81e0f1a5 100644 --- a/packages/browser/src/exports.ts +++ b/packages/browser/src/exports.ts @@ -37,6 +37,7 @@ export { createTransport, flush, getHubFromCarrier, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, getCurrentScope, diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index 136700432dbb..929222400ff9 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -159,6 +159,7 @@ interface ShowReportDialogFunction { export const showReportDialog: ShowReportDialogFunction = ( // eslint-disable-next-line deprecation/deprecation options: ReportDialogOptions = {}, + // eslint-disable-next-line deprecation/deprecation hub: Hub = getCurrentHub(), ) => { // doesn't work without a document (React Native) diff --git a/packages/browser/test/unit/profiling/hubextensions.test.ts b/packages/browser/test/unit/profiling/hubextensions.test.ts index 552b71ca9b81..362379b3f224 100644 --- a/packages/browser/test/unit/profiling/hubextensions.test.ts +++ b/packages/browser/test/unit/profiling/hubextensions.test.ts @@ -4,7 +4,7 @@ const patchedEncoder = (!global.window.TextEncoder && (global.window.TextEncoder // @ts-expect-error patch the encoder on the window, else importing JSDOM fails (deleted in afterAll) const patchedDecoder = (!global.window.TextDecoder && (global.window.TextDecoder = TextDecoder)) || true; -import { getCurrentHub } from '@sentry/core'; +import { setCurrentClient } from '@sentry/core'; import type { Transaction } from '@sentry/types'; import { JSDOM } from 'jsdom'; @@ -30,7 +30,6 @@ describe('BrowserProfilingIntegration', () => { // @ts-expect-error need to override global document global.location = dom.window.location; - const hub = getCurrentHub(); const client: any = { getDsn() { return {}; @@ -47,8 +46,7 @@ describe('BrowserProfilingIntegration', () => { }, }; - // eslint-disable-next-line deprecation/deprecation - hub.bindClient(client); + setCurrentClient(client); }); // Reset back to previous values diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index cc41d3e4f61e..0b980146d5bb 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -42,6 +42,7 @@ export { // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, getCurrentScope, diff --git a/packages/core/src/exports.ts b/packages/core/src/exports.ts index 4dd3cd6cd073..fa011fc672ac 100644 --- a/packages/core/src/exports.ts +++ b/packages/core/src/exports.ts @@ -189,15 +189,17 @@ export function withScope(scope: ScopeInterface | undefined, callback: (scope export function withScope( ...rest: [callback: (scope: Scope) => T] | [scope: ScopeInterface | undefined, callback: (scope: Scope) => T] ): T { + // eslint-disable-next-line deprecation/deprecation + const hub = getCurrentHub(); + // If a scope is defined, we want to make this the active scope instead of the default one if (rest.length === 2) { const [scope, callback] = rest; if (!scope) { // eslint-disable-next-line deprecation/deprecation - return getCurrentHub().withScope(callback); + return hub.withScope(callback); } - const hub = getCurrentHub(); // eslint-disable-next-line deprecation/deprecation return hub.withScope(() => { // eslint-disable-next-line deprecation/deprecation @@ -207,7 +209,7 @@ export function withScope( } // eslint-disable-next-line deprecation/deprecation - return getCurrentHub().withScope(rest[0]); + return hub.withScope(rest[0]); } /** diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index 85d80786cfeb..d0f7c1cf4430 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -712,6 +712,8 @@ export function makeMain(hub: Hub): Hub { * If a hub is already registered in the global carrier but this module * contains a more recent version, it replaces the registered version. * Otherwise, the currently registered hub will be returned. + * + * @deprecated Use the respective replacement method directly instead. */ export function getCurrentHub(): Hub { // Get main carrier (global for every environment) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 6ca0444b6c34..d6c20e8fa27d 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -37,6 +37,7 @@ export { captureSession, } from './exports'; export { + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getIsolationScope, getHubFromCarrier, diff --git a/packages/core/src/sdk.ts b/packages/core/src/sdk.ts index 51757d293f00..f15f6c976e56 100644 --- a/packages/core/src/sdk.ts +++ b/packages/core/src/sdk.ts @@ -2,6 +2,7 @@ import type { Client, ClientOptions } from '@sentry/types'; import { consoleSandbox, logger } from '@sentry/utils'; import { DEBUG_BUILD } from './debug-build'; +import { getCurrentScope } from './exports'; import { getCurrentHub } from './hub'; /** A class object that can instantiate Client objects. */ @@ -29,9 +30,7 @@ export function initAndBind( }); } } - const hub = getCurrentHub(); - // eslint-disable-next-line deprecation/deprecation - const scope = hub.getScope(); + const scope = getCurrentScope(); scope.update(options.initialScope); const client = new clientClass(options); @@ -43,6 +42,7 @@ export function initAndBind( * Make the given client the current client. */ export function setCurrentClient(client: Client): void { + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); // eslint-disable-next-line deprecation/deprecation const top = hub.getStackTop(); diff --git a/packages/core/src/tracing/trace.ts b/packages/core/src/tracing/trace.ts index df3cebb1734d..103c52ea9c0b 100644 --- a/packages/core/src/tracing/trace.ts +++ b/packages/core/src/tracing/trace.ts @@ -141,6 +141,7 @@ export function trace( // eslint-disable-next-line @typescript-eslint/no-empty-function afterFinish: () => void = () => {}, ): T { + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); const scope = getCurrentScope(); // eslint-disable-next-line deprecation/deprecation @@ -182,6 +183,7 @@ export function startSpan(context: StartSpanOptions, callback: (span: Span | const ctx = normalizeContext(context); return withScope(context.scope, scope => { + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); // eslint-disable-next-line deprecation/deprecation const parentSpan = scope.getSpan(); @@ -226,6 +228,7 @@ export function startSpanManual( const ctx = normalizeContext(context); return withScope(context.scope, scope => { + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); // eslint-disable-next-line deprecation/deprecation const parentSpan = scope.getSpan(); @@ -266,6 +269,7 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined { } const ctx = normalizeContext(context); + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); const parentSpan = context.scope ? // eslint-disable-next-line deprecation/deprecation diff --git a/packages/core/src/tracing/transaction.ts b/packages/core/src/tracing/transaction.ts index eb6736d8f59b..38b1661f25f1 100644 --- a/packages/core/src/tracing/transaction.ts +++ b/packages/core/src/tracing/transaction.ts @@ -54,6 +54,7 @@ export class Transaction extends SpanClass implements TransactionInterface { this._measurements = {}; this._contexts = {}; + // eslint-disable-next-line deprecation/deprecation this._hub = hub || getCurrentHub(); this._name = transactionContext.name || ''; diff --git a/packages/core/src/tracing/utils.ts b/packages/core/src/tracing/utils.ts index 13c2cded52e4..cab0eead61f2 100644 --- a/packages/core/src/tracing/utils.ts +++ b/packages/core/src/tracing/utils.ts @@ -10,6 +10,7 @@ import { getCurrentHub } from '../hub'; * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead. */ export function getActiveTransaction(maybeHub?: Hub): T | undefined { + // eslint-disable-next-line deprecation/deprecation const hub = maybeHub || getCurrentHub(); // eslint-disable-next-line deprecation/deprecation const scope = hub.getScope(); diff --git a/packages/core/test/lib/async-context.test.ts b/packages/core/test/lib/async-context.test.ts index 58b44c922b09..a0e9bb16ab36 100644 --- a/packages/core/test/lib/async-context.test.ts +++ b/packages/core/test/lib/async-context.test.ts @@ -3,8 +3,10 @@ import { getCurrentHub, runWithAsyncContext } from '../../src'; describe('runWithAsyncContext()', () => { it('without strategy hubs should be equal', () => { runWithAsyncContext(() => { + // eslint-disable-next-line deprecation/deprecation const hub1 = getCurrentHub(); runWithAsyncContext(() => { + // eslint-disable-next-line deprecation/deprecation const hub2 = getCurrentHub(); expect(hub1).toBe(hub2); }); diff --git a/packages/core/test/lib/sdk.test.ts b/packages/core/test/lib/sdk.test.ts index bd254f7348c2..1484971babf7 100644 --- a/packages/core/test/lib/sdk.test.ts +++ b/packages/core/test/lib/sdk.test.ts @@ -1,4 +1,4 @@ -import { captureCheckIn, getCurrentHub } from '@sentry/core'; +import { Hub, captureCheckIn, makeMain, setCurrentClient } from '@sentry/core'; import type { Client, Integration } from '@sentry/types'; import { installedIntegrations } from '../../src/integration'; @@ -39,21 +39,22 @@ describe('SDK', () => { }); describe('captureCheckIn', () => { + afterEach(function () { + const hub = new Hub(); + // eslint-disable-next-line deprecation/deprecation + makeMain(hub); + }); + it('returns an id when client is defined', () => { - const hub = getCurrentHub(); - jest.spyOn(hub, 'getClient').mockImplementation(() => { - return { - captureCheckIn: () => 'some-id-wasd-1234', - } as unknown as Client; - }); + const client = { + captureCheckIn: () => 'some-id-wasd-1234', + } as unknown as Client; + setCurrentClient(client); expect(captureCheckIn({ monitorSlug: 'gogogo', status: 'in_progress' })).toStrictEqual('some-id-wasd-1234'); }); it('returns an id when client is undefined', () => { - const hub = getCurrentHub(); - jest.spyOn(hub, 'getClient').mockImplementation(() => undefined); - expect(captureCheckIn({ monitorSlug: 'gogogo', status: 'in_progress' })).toStrictEqual(expect.any(String)); }); }); diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index 8d9b90471a7e..143503b58fda 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -41,6 +41,7 @@ export { // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, getCurrentScope, diff --git a/packages/hub/src/index.ts b/packages/hub/src/index.ts index 8f331511aa84..f865df997d29 100644 --- a/packages/hub/src/index.ts +++ b/packages/hub/src/index.ts @@ -41,6 +41,7 @@ export class Scope extends ScopeCore {} /** * @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8. */ +// eslint-disable-next-line deprecation/deprecation export const getCurrentHub = getCurrentHubCore; /** diff --git a/packages/nextjs/test/serverSdk.test.ts b/packages/nextjs/test/serverSdk.test.ts index b31699b12fb3..5b69f3034d55 100644 --- a/packages/nextjs/test/serverSdk.test.ts +++ b/packages/nextjs/test/serverSdk.test.ts @@ -116,9 +116,11 @@ describe('Server init()', () => { }); it("initializes both global hub and domain hub when there's an active domain", () => { + // eslint-disable-next-line deprecation/deprecation const globalHub = getCurrentHub(); runWithAsyncContext(() => { + // eslint-disable-next-line deprecation/deprecation const globalHub2 = getCurrentHub(); // If we call runWithAsyncContext before init, it executes the callback in the same context as there is no // strategy yet @@ -131,6 +133,7 @@ describe('Server init()', () => { init({}); runWithAsyncContext(() => { + // eslint-disable-next-line deprecation/deprecation const domainHub = getCurrentHub(); // this tag should end up only in the domain hub // eslint-disable-next-line deprecation/deprecation diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index 91cba6748918..73d34526a658 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -41,6 +41,7 @@ export { // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, getCurrentScope, diff --git a/packages/node/test/async/domain.test.ts b/packages/node/test/async/domain.test.ts index f5323e4bca91..19c269466792 100644 --- a/packages/node/test/async/domain.test.ts +++ b/packages/node/test/async/domain.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable deprecation/deprecation */ import { Hub, makeMain } from '@sentry/core'; import { getIsolationScope, withIsolationScope } from '@sentry/core'; import { getCurrentHub, runWithAsyncContext, setAsyncContextStrategy } from '@sentry/core'; diff --git a/packages/node/test/async/hooks.test.ts b/packages/node/test/async/hooks.test.ts index 991b7456d6fa..f016a7087e4f 100644 --- a/packages/node/test/async/hooks.test.ts +++ b/packages/node/test/async/hooks.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable deprecation/deprecation */ import { Hub, getCurrentHub, diff --git a/packages/node/test/index.test.ts b/packages/node/test/index.test.ts index 4d54b042a117..6add4b35f97f 100644 --- a/packages/node/test/index.test.ts +++ b/packages/node/test/index.test.ts @@ -303,6 +303,7 @@ describe('SentryNode', () => { const client = new NodeClient(options); runWithAsyncContext(() => { + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); setCurrentClient(client); client.init(); diff --git a/packages/opentelemetry-node/src/spanprocessor.ts b/packages/opentelemetry-node/src/spanprocessor.ts index dcec2ebeef43..8e7b54684469 100644 --- a/packages/opentelemetry-node/src/spanprocessor.ts +++ b/packages/opentelemetry-node/src/spanprocessor.ts @@ -119,6 +119,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor { return; } + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); otelSpan.events.forEach(event => { maybeCaptureExceptionForTimedEvent(hub, event, otelSpan); @@ -126,7 +127,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor { if (sentrySpan instanceof Transaction) { updateTransactionWithOtelData(sentrySpan, otelSpan); - sentrySpan.setHub(getCurrentHub()); + sentrySpan.setHub(hub); } else { updateSpanWithOtelData(sentrySpan, otelSpan); } diff --git a/packages/react/src/profiler.tsx b/packages/react/src/profiler.tsx index d8ee675ea742..804e7821d7d2 100644 --- a/packages/react/src/profiler.tsx +++ b/packages/react/src/profiler.tsx @@ -225,7 +225,10 @@ function useProfiler( export { withProfiler, Profiler, useProfiler }; /** Grabs active transaction off scope */ -export function getActiveTransaction(hub: Hub = getCurrentHub()): T | undefined { +export function getActiveTransaction( + // eslint-disable-next-line deprecation/deprecation + hub: Hub = getCurrentHub(), +): T | undefined { if (hub) { // eslint-disable-next-line deprecation/deprecation const scope = hub.getScope(); diff --git a/packages/remix/src/index.server.ts b/packages/remix/src/index.server.ts index 22ba1883b0d5..86be1ff8dd2d 100644 --- a/packages/remix/src/index.server.ts +++ b/packages/remix/src/index.server.ts @@ -28,6 +28,7 @@ export { // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, Hub, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/remix/src/utils/instrumentServer.ts b/packages/remix/src/utils/instrumentServer.ts index 7a7ec540e469..6c77cab75272 100644 --- a/packages/remix/src/utils/instrumentServer.ts +++ b/packages/remix/src/utils/instrumentServer.ts @@ -452,6 +452,7 @@ function wrapRequestHandler(origRequestHandler: RequestHandler, build: ServerBui } return runWithAsyncContext(async () => { + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); const options = getClient()?.getOptions(); const scope = getCurrentScope(); diff --git a/packages/remix/src/utils/serverAdapters/express.ts b/packages/remix/src/utils/serverAdapters/express.ts index fd0af832c2f5..d3acd7633132 100644 --- a/packages/remix/src/utils/serverAdapters/express.ts +++ b/packages/remix/src/utils/serverAdapters/express.ts @@ -50,6 +50,7 @@ function wrapExpressRequestHandler( res.end = wrapEndMethod(res.end); const request = extractRequestData(req); + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); const options = getClient()?.getOptions(); const scope = getCurrentScope(); diff --git a/packages/replay/test/unit/session/createSession.test.ts b/packages/replay/test/unit/session/createSession.test.ts index 891cc012edb6..2fc8779a5acb 100644 --- a/packages/replay/test/unit/session/createSession.test.ts +++ b/packages/replay/test/unit/session/createSession.test.ts @@ -1,4 +1,5 @@ import * as Sentry from '@sentry/core'; +import type { Hub } from '@sentry/core'; import { WINDOW } from '../../../src/constants'; import { createSession } from '../../../src/session/createSession'; @@ -20,10 +21,11 @@ describe('Unit | session | createSession', () => { beforeAll(() => { WINDOW.sessionStorage.clear(); - jest.spyOn(Sentry, 'getCurrentHub'); - (Sentry.getCurrentHub as jest.Mock).mockImplementation(() => ({ - captureEvent: captureEventMock, - })); + jest.spyOn(Sentry, 'getCurrentHub').mockImplementation(() => { + return { + captureEvent: captureEventMock, + } as unknown as Hub; + }); }); afterEach(() => { diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.ts index f5cc51789a79..824f2d1374f6 100644 --- a/packages/serverless/src/index.ts +++ b/packages/serverless/src/index.ts @@ -29,6 +29,7 @@ export { createTransport, // eslint-disable-next-line deprecation/deprecation getActiveTransaction, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, getCurrentScope, diff --git a/packages/sveltekit/src/server/index.ts b/packages/sveltekit/src/server/index.ts index 5e4e13960774..f57f7c817b91 100644 --- a/packages/sveltekit/src/server/index.ts +++ b/packages/sveltekit/src/server/index.ts @@ -22,6 +22,7 @@ export { // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, getCurrentScope, diff --git a/packages/tracing-internal/src/node/integrations/prisma.ts b/packages/tracing-internal/src/node/integrations/prisma.ts index 6a9a4ac6b52e..f51bcd6eef32 100644 --- a/packages/tracing-internal/src/node/integrations/prisma.ts +++ b/packages/tracing-internal/src/node/integrations/prisma.ts @@ -92,6 +92,7 @@ export class Prisma implements Integration { } options.client.$use((params, next: (params: PrismaMiddlewareParams) => Promise) => { + // eslint-disable-next-line deprecation/deprecation if (shouldDisableAutoInstrumentation(getCurrentHub)) { return next(params); } diff --git a/packages/tracing/test/index.test.ts b/packages/tracing/test/index.test.ts index e30bb92c0e5d..ea35353868ca 100644 --- a/packages/tracing/test/index.test.ts +++ b/packages/tracing/test/index.test.ts @@ -4,6 +4,7 @@ import { BrowserTracing, Integrations } from '../src'; describe('index', () => { it('patches the global hub to add an implementation for `Hub.startTransaction` as a side effect', () => { + // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub(); // eslint-disable-next-line deprecation/deprecation const transaction = hub.startTransaction({ name: 'test', endTimestamp: 123 }); diff --git a/packages/vercel-edge/src/index.ts b/packages/vercel-edge/src/index.ts index 0e2606ebb33b..d23a8215f76f 100644 --- a/packages/vercel-edge/src/index.ts +++ b/packages/vercel-edge/src/index.ts @@ -41,6 +41,7 @@ export { // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, + // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, getCurrentScope, diff --git a/packages/vue/src/integration.ts b/packages/vue/src/integration.ts index 1d3bfa47cc19..f6477dfb8999 100644 --- a/packages/vue/src/integration.ts +++ b/packages/vue/src/integration.ts @@ -1,5 +1,5 @@ import { hasTracingEnabled } from '@sentry/core'; -import type { Hub, Integration } from '@sentry/types'; +import type { Client, Hub, Integration } from '@sentry/types'; import { GLOBAL_OBJ, arrayify, consoleSandbox } from '@sentry/utils'; import { DEFAULT_HOOKS } from './constants'; @@ -41,13 +41,12 @@ export class VueIntegration implements Integration { /** @inheritDoc */ public setupOnce(_addGlobalEventProcessor: unknown, getCurrentHub: () => Hub): void { - this._setupIntegration(getCurrentHub()); + // eslint-disable-next-line deprecation/deprecation + this._setupIntegration(getCurrentHub().getClient()); } /** Just here for easier testing */ - protected _setupIntegration(hub: Hub): void { - // eslint-disable-next-line deprecation/deprecation - const client = hub.getClient(); + protected _setupIntegration(client: Client | undefined): void { const options: Options = { ...DEFAULT_CONFIG, ...(client && client.getOptions()), ...this._options }; if (!options.Vue && !options.app) { diff --git a/packages/vue/test/integration/VueIntegration.test.ts b/packages/vue/test/integration/VueIntegration.test.ts index 22f53df4c498..335133296e06 100644 --- a/packages/vue/test/integration/VueIntegration.test.ts +++ b/packages/vue/test/integration/VueIntegration.test.ts @@ -36,7 +36,7 @@ describe('Sentry.VueIntegration', () => { // This would normally happen through client.addIntegration() const integration = new Sentry.VueIntegration({ app }); - integration['_setupIntegration'](Sentry.getCurrentHub()); + integration['_setupIntegration'](Sentry.getClient()); app.mount(el); @@ -58,7 +58,7 @@ describe('Sentry.VueIntegration', () => { // This would normally happen through client.addIntegration() const integration = new Sentry.VueIntegration({ app }); - integration['_setupIntegration'](Sentry.getCurrentHub()); + integration['_setupIntegration'](Sentry.getClient()); expect(warnings).toEqual([ '[@sentry/vue]: Misconfigured SDK. Vue app is already mounted. Make sure to call `app.mount()` after `Sentry.init()`.', diff --git a/packages/vue/test/integration/init.test.ts b/packages/vue/test/integration/init.test.ts index ed69034ebbf7..557f3fc694e2 100644 --- a/packages/vue/test/integration/init.test.ts +++ b/packages/vue/test/integration/init.test.ts @@ -119,6 +119,6 @@ function runInit(options: Partial): void { // If we've already had this integration registered before // if that's the case, `setup()` will not be run, so we need to manually run it :( if (hasRunBefore) { - integration['_setupIntegration'](Sentry.getCurrentHub()); + integration['_setupIntegration'](Sentry.getClient()); } }