Skip to content

Commit 481debb

Browse files
authored
feat: Hoist getCurrentHub shim to core as getCurrentHubShim (#11537)
1 parent 700562d commit 481debb

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

packages/opentelemetry/src/custom/getCurrentHub.ts renamed to packages/core/src/getCurrentHubShim.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import type { Client, EventHint, Hub, Integration, IntegrationClass, SeverityLevel } from '@sentry/types';
2-
2+
import { addBreadcrumb } from './breadcrumbs';
3+
import { getClient, getCurrentScope, getIsolationScope, withScope } from './currentScopes';
34
import {
4-
addBreadcrumb,
55
captureEvent,
66
endSession,
7-
getClient,
8-
getCurrentScope,
9-
getIsolationScope,
107
setContext,
118
setExtra,
129
setExtras,
1310
setTag,
1411
setTags,
1512
setUser,
1613
startSession,
17-
withScope,
18-
} from '@sentry/core';
14+
} from './exports';
1915

2016
/**
2117
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.
18+
*
2219
* @deprecated Use the methods directly.
2320
*/
24-
export function getCurrentHub(): Hub {
21+
export function getCurrentHubShim(): Hub {
2522
return {
2623
bindClient(client: Client): void {
2724
const scope = getCurrentScope();
@@ -48,7 +45,8 @@ export function getCurrentHub(): Hub {
4845
setContext,
4946

5047
getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {
51-
return getClient()?.getIntegrationByName<T>(integration.id) || null;
48+
const client = getClient();
49+
return (client && client.getIntegrationByName<T>(integration.id)) || null;
5250
},
5351

5452
startSession,

packages/core/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ export { BrowserMetricsAggregator } from './metrics/browser-aggregator';
106106
export { getMetricSummaryJsonForSpan } from './metrics/metric-summary';
107107
export { addTracingHeadersToFetchRequest, instrumentFetchRequest } from './fetch';
108108
export { trpcMiddleware } from './trpc';
109+
110+
// eslint-disable-next-line deprecation/deprecation
111+
export { getCurrentHubShim } from './getCurrentHubShim';

packages/opentelemetry/src/asyncContextStrategy.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as api from '@opentelemetry/api';
2-
import { getDefaultCurrentScope, getDefaultIsolationScope, setAsyncContextStrategy } from '@sentry/core';
2+
import {
3+
getCurrentHubShim,
4+
getDefaultCurrentScope,
5+
getDefaultIsolationScope,
6+
setAsyncContextStrategy,
7+
} from '@sentry/core';
38
import type { withActiveSpan as defaultWithActiveSpan } from '@sentry/core';
49
import type { Hub, Scope } from '@sentry/types';
510

@@ -8,7 +13,6 @@ import {
813
SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY,
914
SENTRY_FORK_SET_SCOPE_CONTEXT_KEY,
1015
} from './constants';
11-
import { getCurrentHub as _getCurrentHub } from './custom/getCurrentHub';
1216
import { startInactiveSpan, startSpan, startSpanManual, withActiveSpan } from './trace';
1317
import type { CurrentScopes } from './types';
1418
import { getScopesFromContext } from './utils/contextData';
@@ -38,7 +42,7 @@ export function setOpenTelemetryContextAsyncContextStrategy(): void {
3842

3943
function getCurrentHub(): Hub {
4044
// eslint-disable-next-line deprecation/deprecation
41-
const hub = _getCurrentHub();
45+
const hub = getCurrentHubShim();
4246
return {
4347
...hub,
4448
getScope: () => {

packages/opentelemetry/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export { suppressTracing } from './utils/suppressTracing';
2828
// eslint-disable-next-line deprecation/deprecation
2929
export { setupGlobalHub } from './custom/hub';
3030
// eslint-disable-next-line deprecation/deprecation
31-
export { getCurrentHub } from './custom/getCurrentHub';
31+
export { getCurrentHubShim } from '@sentry/core';
3232
export { setupEventContextTrace } from './setupEventContextTrace';
3333

3434
export { setOpenTelemetryContextAsyncContextStrategy } from './asyncContextStrategy';

0 commit comments

Comments
 (0)