From 496995c09669289baff25a01bbbe7f575427c8fc Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 10 Apr 2024 14:19:21 +0000 Subject: [PATCH 1/3] feat: Hoist `getCurrentHub` shim to core as `getCurrentHubShim` --- .../src/custom/getCurrentHub.ts => core/src/getCurrentHubShim.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/{opentelemetry/src/custom/getCurrentHub.ts => core/src/getCurrentHubShim.ts} (100%) diff --git a/packages/opentelemetry/src/custom/getCurrentHub.ts b/packages/core/src/getCurrentHubShim.ts similarity index 100% rename from packages/opentelemetry/src/custom/getCurrentHub.ts rename to packages/core/src/getCurrentHubShim.ts From 7cf8268d9b932a4f049eebe198e127b419e7a8aa Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 10 Apr 2024 14:21:31 +0000 Subject: [PATCH 2/3] Adjust for core --- packages/core/src/getCurrentHubShim.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/core/src/getCurrentHubShim.ts b/packages/core/src/getCurrentHubShim.ts index 9db09297d670..0880a4a0ab85 100644 --- a/packages/core/src/getCurrentHubShim.ts +++ b/packages/core/src/getCurrentHubShim.ts @@ -1,12 +1,9 @@ import type { Client, EventHint, Hub, Integration, IntegrationClass, SeverityLevel } from '@sentry/types'; - +import { addBreadcrumb } from './breadcrumbs'; +import { getClient, getCurrentScope, getIsolationScope, withScope } from './currentScopes'; import { - addBreadcrumb, captureEvent, endSession, - getClient, - getCurrentScope, - getIsolationScope, setContext, setExtra, setExtras, @@ -14,8 +11,7 @@ import { setTags, setUser, startSession, - withScope, -} from '@sentry/core'; +} from './exports'; /** * This is for legacy reasons, and returns a proxy object instead of a hub to be used. @@ -48,7 +44,8 @@ export function getCurrentHub(): Hub { setContext, getIntegration(integration: IntegrationClass): T | null { - return getClient()?.getIntegrationByName(integration.id) || null; + const client = getClient(); + return (client && client.getIntegrationByName(integration.id)) || null; }, startSession, From 1ce9030a10562a01f40fc1a992f923170650d513 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 10 Apr 2024 14:27:45 +0000 Subject: [PATCH 3/3] Update usages --- packages/core/src/getCurrentHubShim.ts | 3 ++- packages/core/src/index.ts | 3 +++ packages/opentelemetry/src/asyncContextStrategy.ts | 10 +++++++--- packages/opentelemetry/src/index.ts | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/core/src/getCurrentHubShim.ts b/packages/core/src/getCurrentHubShim.ts index 0880a4a0ab85..435004ce9f57 100644 --- a/packages/core/src/getCurrentHubShim.ts +++ b/packages/core/src/getCurrentHubShim.ts @@ -15,9 +15,10 @@ import { /** * This is for legacy reasons, and returns a proxy object instead of a hub to be used. + * * @deprecated Use the methods directly. */ -export function getCurrentHub(): Hub { +export function getCurrentHubShim(): Hub { return { bindClient(client: Client): void { const scope = getCurrentScope(); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 48bb5baf6afc..e3f827605aeb 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -106,3 +106,6 @@ export { BrowserMetricsAggregator } from './metrics/browser-aggregator'; export { getMetricSummaryJsonForSpan } from './metrics/metric-summary'; export { addTracingHeadersToFetchRequest, instrumentFetchRequest } from './fetch'; export { trpcMiddleware } from './trpc'; + +// eslint-disable-next-line deprecation/deprecation +export { getCurrentHubShim } from './getCurrentHubShim'; diff --git a/packages/opentelemetry/src/asyncContextStrategy.ts b/packages/opentelemetry/src/asyncContextStrategy.ts index b7f66870d07f..e28995a5d805 100644 --- a/packages/opentelemetry/src/asyncContextStrategy.ts +++ b/packages/opentelemetry/src/asyncContextStrategy.ts @@ -1,5 +1,10 @@ import * as api from '@opentelemetry/api'; -import { getDefaultCurrentScope, getDefaultIsolationScope, setAsyncContextStrategy } from '@sentry/core'; +import { + getCurrentHubShim, + getDefaultCurrentScope, + getDefaultIsolationScope, + setAsyncContextStrategy, +} from '@sentry/core'; import type { withActiveSpan as defaultWithActiveSpan } from '@sentry/core'; import type { Hub, Scope } from '@sentry/types'; @@ -8,7 +13,6 @@ import { SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, SENTRY_FORK_SET_SCOPE_CONTEXT_KEY, } from './constants'; -import { getCurrentHub as _getCurrentHub } from './custom/getCurrentHub'; import { startInactiveSpan, startSpan, startSpanManual, withActiveSpan } from './trace'; import type { CurrentScopes } from './types'; import { getScopesFromContext } from './utils/contextData'; @@ -38,7 +42,7 @@ export function setOpenTelemetryContextAsyncContextStrategy(): void { function getCurrentHub(): Hub { // eslint-disable-next-line deprecation/deprecation - const hub = _getCurrentHub(); + const hub = getCurrentHubShim(); return { ...hub, getScope: () => { diff --git a/packages/opentelemetry/src/index.ts b/packages/opentelemetry/src/index.ts index 3d727c707897..db5abb951f4c 100644 --- a/packages/opentelemetry/src/index.ts +++ b/packages/opentelemetry/src/index.ts @@ -28,7 +28,7 @@ export { suppressTracing } from './utils/suppressTracing'; // eslint-disable-next-line deprecation/deprecation export { setupGlobalHub } from './custom/hub'; // eslint-disable-next-line deprecation/deprecation -export { getCurrentHub } from './custom/getCurrentHub'; +export { getCurrentHubShim } from '@sentry/core'; export { setupEventContextTrace } from './setupEventContextTrace'; export { setOpenTelemetryContextAsyncContextStrategy } from './asyncContextStrategy';