diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index 0c046e855e8d..7a8ff4427e12 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -16,7 +16,6 @@ export { captureCheckIn, withMonitor, createTransport, - getHubFromCarrier, // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, diff --git a/packages/browser/src/exports.ts b/packages/browser/src/exports.ts index 82a524f2bf76..301c681dc14a 100644 --- a/packages/browser/src/exports.ts +++ b/packages/browser/src/exports.ts @@ -31,7 +31,6 @@ export { close, createTransport, flush, - getHubFromCarrier, // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, diff --git a/packages/browser/test/unit/index.test.ts b/packages/browser/test/unit/index.test.ts index 46104ba79b0f..6272adc653b8 100644 --- a/packages/browser/test/unit/index.test.ts +++ b/packages/browser/test/unit/index.test.ts @@ -58,21 +58,21 @@ describe('SentryBrowser', () => { describe('getContext() / setContext()', () => { it('should store/load extra', () => { getCurrentScope().setExtra('abc', { def: [1] }); - expect(global.__SENTRY__.hub._stack[0].scope._extra).toEqual({ + expect(getCurrentScope().getScopeData().extra).toEqual({ abc: { def: [1] }, }); }); it('should store/load tags', () => { getCurrentScope().setTag('abc', 'def'); - expect(global.__SENTRY__.hub._stack[0].scope._tags).toEqual({ + expect(getCurrentScope().getScopeData().tags).toEqual({ abc: 'def', }); }); it('should store/load user', () => { getCurrentScope().setUser({ id: 'def' }); - expect(global.__SENTRY__.hub._stack[0].scope._user).toEqual({ + expect(getCurrentScope().getScopeData().user).toEqual({ id: 'def', }); }); @@ -294,20 +294,20 @@ describe('SentryBrowser initialization', () => { it('should use window.SENTRY_RELEASE to set release on initialization if available', () => { global.SENTRY_RELEASE = { id: 'foobar' }; init({ dsn }); - expect(global.__SENTRY__.hub._stack[0].client.getOptions().release).toBe('foobar'); + expect(getClient()?.getOptions().release).toBe('foobar'); delete global.SENTRY_RELEASE; }); it('should use initialScope', () => { init({ dsn, initialScope: { tags: { a: 'b' } } }); - expect(global.__SENTRY__.hub._stack[0].scope._tags).toEqual({ a: 'b' }); + expect(getCurrentScope().getScopeData().tags).toEqual({ a: 'b' }); }); it('should use initialScope Scope', () => { const scope = new Scope(); scope.setTags({ a: 'b' }); init({ dsn, initialScope: scope }); - expect(global.__SENTRY__.hub._stack[0].scope._tags).toEqual({ a: 'b' }); + expect(getCurrentScope().getScopeData().tags).toEqual({ a: 'b' }); }); it('should use initialScope callback', () => { @@ -318,13 +318,13 @@ describe('SentryBrowser initialization', () => { return scope; }, }); - expect(global.__SENTRY__.hub._stack[0].scope._tags).toEqual({ a: 'b' }); + expect(getCurrentScope().getScopeData().tags).toEqual({ a: 'b' }); }); it('should have initialization proceed as normal if window.SENTRY_RELEASE is not set', () => { // This is mostly a happy-path test to ensure that the initialization doesn't throw an error. init({ dsn }); - expect(global.__SENTRY__.hub._stack[0].client.getOptions().release).toBeUndefined(); + expect(getClient()?.getOptions().release).toBeUndefined(); }); describe('SDK metadata', () => { diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 28ffa8f73d84..6b06bd604244 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -35,7 +35,6 @@ export { flush, // eslint-disable-next-line deprecation/deprecation getActiveTransaction, - getHubFromCarrier, // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, diff --git a/packages/core/src/asyncContext.ts b/packages/core/src/asyncContext.ts index 9ff2fff996f0..fa47ce8aa020 100644 --- a/packages/core/src/asyncContext.ts +++ b/packages/core/src/asyncContext.ts @@ -53,7 +53,6 @@ export interface Carrier { } interface SentryCarrier { - hub?: Hub; acs?: AsyncContextStrategy; /** * Extra Hub properties injected by various SDKs @@ -96,7 +95,6 @@ export function getSentryCarrier(carrier: Carrier): SentryCarrier { if (!carrier.__SENTRY__) { carrier.__SENTRY__ = { extensions: {}, - hub: undefined, }; } return carrier.__SENTRY__; diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index f092af47f512..0fa6d239a26f 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -421,20 +421,6 @@ export class Hub implements HubInterface { this.getIsolationScope().setContext(name, context); } - /** - * @inheritDoc - */ - public run(callback: (hub: Hub) => void): void { - // eslint-disable-next-line deprecation/deprecation - const oldHub = makeMain(this); - try { - callback(this); - } finally { - // eslint-disable-next-line deprecation/deprecation - makeMain(oldHub); - } - } - /** * @inheritDoc * @deprecated Use `Sentry.getClient().getIntegrationByName()` instead. @@ -618,23 +604,8 @@ Sentry.init({...}); * @deprecated Use `setCurrentClient()` instead. */ export function makeMain(hub: HubInterface): HubInterface { - const registry = getMainCarrier(); - const oldHub = getHubFromCarrier(registry); - setHubOnCarrier(registry, hub); - return oldHub; -} - -/** - * This will set passed {@link Hub} on the passed object's __SENTRY__.hub attribute - * @param carrier object - * @param hub Hub - * @returns A boolean indicating success or failure - */ -export function setHubOnCarrier(carrier: Carrier, hub: HubInterface): boolean { - if (!carrier) return false; - const sentry = getSentryCarrier(carrier); - sentry.hub = hub; - return true; + // noop! + return hub; } /** @@ -681,69 +652,18 @@ export function getDefaultIsolationScope(): Scope { */ export function getGlobalHub(): HubInterface { const registry = getMainCarrier(); + const sentry = getSentryCarrier(registry) as { hub?: HubInterface }; // If there's no hub, or its an old API, assign a new one - - if ( - !hasHubOnCarrier(registry) || - // eslint-disable-next-line deprecation/deprecation - getHubFromCarrier(registry).isOlderThan(API_VERSION) - ) { - // eslint-disable-next-line deprecation/deprecation - setHubOnCarrier(registry, new Hub(undefined, getDefaultCurrentScope(), getDefaultIsolationScope())); - } - - // Return hub that lives on a global object - return getHubFromCarrier(registry); -} - -/** - * This will tell whether a carrier has a hub on it or not - * @param carrier object - */ -function hasHubOnCarrier(carrier: Carrier): boolean { - return !!getSentryCarrier(carrier).hub; -} - -/** - * This will create a new {@link Hub} and add to the passed object on - * __SENTRY__.hub. - * @param carrier object - * @hidden - */ -export function getHubFromCarrier(carrier: Carrier): HubInterface { - const sentry = getSentryCarrier(carrier); - if (!sentry.hub) { - // eslint-disable-next-line deprecation/deprecation - sentry.hub = new Hub(); + if (sentry.hub) { + return sentry.hub; } + // eslint-disable-next-line deprecation/deprecation + sentry.hub = new Hub(undefined, getDefaultCurrentScope(), getDefaultIsolationScope()); return sentry.hub; } -/** - * @private Private API with no semver guarantees! - * - * If the carrier does not contain a hub, a new hub is created with the global hub client and scope. - */ -export function ensureHubOnCarrier(carrier: Carrier, parent: HubInterface = getGlobalHub()): void { - // If there's no hub on current domain, or it's an old API, assign a new one - if ( - !hasHubOnCarrier(carrier) || - // eslint-disable-next-line deprecation/deprecation - getHubFromCarrier(carrier).isOlderThan(API_VERSION) - ) { - // eslint-disable-next-line deprecation/deprecation - const client = parent.getClient(); - // eslint-disable-next-line deprecation/deprecation - const scope = parent.getScope(); - // eslint-disable-next-line deprecation/deprecation - const isolationScope = parent.getIsolationScope(); - // eslint-disable-next-line deprecation/deprecation - setHubOnCarrier(carrier, new Hub(client, scope.clone() as Scope, isolationScope.clone() as Scope)); - } -} - /** * Get the current async context strategy. * If none has been setup, the default will be used. diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 8e69f6aba5af..56d86d3426c9 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -35,12 +35,9 @@ export { export { // eslint-disable-next-line deprecation/deprecation getCurrentHub, - getHubFromCarrier, Hub, // eslint-disable-next-line deprecation/deprecation makeMain, - setHubOnCarrier, - ensureHubOnCarrier, getGlobalHub, getDefaultCurrentScope, getDefaultIsolationScope, diff --git a/packages/core/test/lib/global.test.ts b/packages/core/test/lib/global.test.ts deleted file mode 100644 index 7e6bdf58ac9e..000000000000 --- a/packages/core/test/lib/global.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* eslint-disable deprecation/deprecation */ - -import { GLOBAL_OBJ } from '@sentry/utils'; - -import { Hub, getCurrentHub, getHubFromCarrier } from '../../src/hub'; - -describe('global', () => { - test('getGlobalHub', () => { - expect(getCurrentHub()).toBeTruthy(); - expect(GLOBAL_OBJ.__SENTRY__.hub).toBeTruthy(); - }); - - test('getHubFromCarrier', () => { - const bla = { a: 'b' }; - getHubFromCarrier(bla as any); - expect((bla as any).__SENTRY__.hub).toBeTruthy(); - expect((bla as any).__SENTRY__.hub).toBe((bla as any).__SENTRY__.hub); - getHubFromCarrier(bla as any); - }); - - test('getGlobalHub', () => { - const newestHub = new Hub(undefined, undefined, undefined, 999999); - GLOBAL_OBJ.__SENTRY__.hub = newestHub; - expect(getCurrentHub()).toBe(newestHub); - }); - - test('hub extension methods receive correct hub instance', () => { - const newestHub = new Hub(undefined, undefined, undefined, 999999); - GLOBAL_OBJ.__SENTRY__.hub = newestHub; - const fn = jest.fn().mockImplementation(function (...args: []) { - // @ts-expect-error 'this' implicitly has type 'any' because it does not have a type annotation - expect(this).toBe(newestHub); - expect(args).toEqual([1, 2, 3]); - }); - GLOBAL_OBJ.__SENTRY__.extensions = {}; - GLOBAL_OBJ.__SENTRY__.extensions.testy = fn; - (getCurrentHub() as any)._callExtensionMethod('testy', 1, 2, 3); - expect(fn).toBeCalled(); - }); -}); diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index fd325263e84f..873cb4ba2b38 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -34,7 +34,6 @@ export { flush, // eslint-disable-next-line deprecation/deprecation getActiveTransaction, - getHubFromCarrier, // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, diff --git a/packages/node-experimental/src/sdk/hub.ts b/packages/node-experimental/src/sdk/hub.ts index ef652ba01fbf..4de88d4788c7 100644 --- a/packages/node-experimental/src/sdk/hub.ts +++ b/packages/node-experimental/src/sdk/hub.ts @@ -72,11 +72,6 @@ export function getCurrentHub(): Hub { setExtras, setContext, - run(callback: (hub: Hub) => void): void { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return withScope(() => callback(this as any)); - }, - getIntegration(integration: IntegrationClass): T | null { // eslint-disable-next-line deprecation/deprecation return getClient().getIntegration(integration); diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index 713a2571f72e..519e969af141 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -34,7 +34,6 @@ export { flush, // eslint-disable-next-line deprecation/deprecation getActiveTransaction, - getHubFromCarrier, // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, diff --git a/packages/node/test/handlers.test.ts b/packages/node/test/handlers.test.ts index 960d25e7bcad..f64aa08a9129 100644 --- a/packages/node/test/handlers.test.ts +++ b/packages/node/test/handlers.test.ts @@ -28,7 +28,6 @@ describe('requestHandler', () => { const sentry = getMainCarrier().__SENTRY__; if (sentry) { sentry.acs = undefined; - sentry.hub = undefined; } }); @@ -205,7 +204,6 @@ describe('tracingHandler', () => { const sentry = getMainCarrier().__SENTRY__; if (sentry) { sentry.acs = undefined; - sentry.hub = undefined; } }); @@ -524,7 +522,6 @@ describe('errorHandler()', () => { const sentry = getMainCarrier().__SENTRY__; if (sentry) { sentry.acs = undefined; - sentry.hub = undefined; } }); diff --git a/packages/node/test/index.test.ts b/packages/node/test/index.test.ts index 70061fe1d01c..3b9a52272b61 100644 --- a/packages/node/test/index.test.ts +++ b/packages/node/test/index.test.ts @@ -56,21 +56,22 @@ describe('SentryNode', () => { describe('getContext() / setContext()', () => { test('store/load extra', async () => { getCurrentScope().setExtra('abc', { def: [1] }); - expect(global.__SENTRY__.hub._stack[0].scope._extra).toEqual({ + + expect(getCurrentScope().getScopeData().extra).toEqual({ abc: { def: [1] }, }); }); test('store/load tags', async () => { getCurrentScope().setTag('abc', 'def'); - expect(global.__SENTRY__.hub._stack[0].scope._tags).toEqual({ + expect(getCurrentScope().getScopeData().tags).toEqual({ abc: 'def', }); }); test('store/load user', async () => { getCurrentScope().setUser({ id: 'def' }); - expect(global.__SENTRY__.hub._stack[0].scope._user).toEqual({ + expect(getCurrentScope().getScopeData().user).toEqual({ id: 'def', }); }); @@ -384,7 +385,7 @@ describe('SentryNode initialization', () => { test('global.SENTRY_RELEASE is used to set release on initialization if available', () => { global.SENTRY_RELEASE = { id: 'foobar' }; init({ dsn }); - expect(global.__SENTRY__.hub._stack[0].client.getOptions().release).toEqual('foobar'); + expect(getClient()?.getOptions().release).toEqual('foobar'); // Unsure if this is needed under jest. global.SENTRY_RELEASE = undefined; }); diff --git a/packages/node/test/integrations/undici.test.ts b/packages/node/test/integrations/undici.test.ts index 7119fb375b82..9bd28d33c713 100644 --- a/packages/node/test/integrations/undici.test.ts +++ b/packages/node/test/integrations/undici.test.ts @@ -44,7 +44,6 @@ beforeEach(() => { const sentry = getMainCarrier().__SENTRY__; if (sentry) { sentry.acs = undefined; - sentry.hub = undefined; } getCurrentScope().clear(); diff --git a/packages/opentelemetry/src/custom/getCurrentHub.ts b/packages/opentelemetry/src/custom/getCurrentHub.ts index 3e4f6639d188..5df6e1e1d36f 100644 --- a/packages/opentelemetry/src/custom/getCurrentHub.ts +++ b/packages/opentelemetry/src/custom/getCurrentHub.ts @@ -71,11 +71,6 @@ export function getCurrentHub(): Hub { setExtras, setContext, - run(callback: (hub: Hub) => void): void { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return withScope(() => callback(this as any)); - }, - getIntegration(integration: IntegrationClass): T | null { // eslint-disable-next-line deprecation/deprecation return getClient()?.getIntegration(integration) || null; diff --git a/packages/remix/src/index.server.ts b/packages/remix/src/index.server.ts index 9990595125e6..3f106fc8eecf 100644 --- a/packages/remix/src/index.server.ts +++ b/packages/remix/src/index.server.ts @@ -23,7 +23,6 @@ export { createTransport, // eslint-disable-next-line deprecation/deprecation getActiveTransaction, - getHubFromCarrier, // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.ts index f02117ce33c1..03a8539bf8f4 100644 --- a/packages/serverless/src/index.ts +++ b/packages/serverless/src/index.ts @@ -35,7 +35,6 @@ export { getCurrentScope, getGlobalScope, getIsolationScope, - getHubFromCarrier, getSpanStatusFromHttpCode, setHttpStatus, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/sveltekit/src/server/index.ts b/packages/sveltekit/src/server/index.ts index e31d15f50eb1..44e073da8ece 100644 --- a/packages/sveltekit/src/server/index.ts +++ b/packages/sveltekit/src/server/index.ts @@ -17,7 +17,6 @@ export { createTransport, // eslint-disable-next-line deprecation/deprecation getActiveTransaction, - getHubFromCarrier, // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient, diff --git a/packages/types/src/hub.ts b/packages/types/src/hub.ts index 61463b9e98b1..7eec8d42b91a 100644 --- a/packages/types/src/hub.ts +++ b/packages/types/src/hub.ts @@ -197,15 +197,6 @@ export interface Hub { */ setContext(name: string, context: { [key: string]: any } | null): void; - /** - * For the duration of the callback, this hub will be set as the global current Hub. - * This function is useful if you want to run your own client and hook into an already initialized one - * e.g.: Reporting issues to your own sentry when running in your component while still using the users configuration. - * - * TODO v8: This will be merged with `withScope()` - */ - run(callback: (hub: Hub) => void): void; - /** * Returns the integration if installed on the current client. * diff --git a/packages/vercel-edge/src/index.ts b/packages/vercel-edge/src/index.ts index 6374b534705e..416be96797f1 100644 --- a/packages/vercel-edge/src/index.ts +++ b/packages/vercel-edge/src/index.ts @@ -34,7 +34,6 @@ export { flush, // eslint-disable-next-line deprecation/deprecation getActiveTransaction, - getHubFromCarrier, // eslint-disable-next-line deprecation/deprecation getCurrentHub, getClient,