Skip to content

feat: Hoist getCurrentHub shim to core as getCurrentHubShim #11537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
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,
setTag,
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.
*
* @deprecated Use the methods directly.
*/
export function getCurrentHub(): Hub {
export function getCurrentHubShim(): Hub {
return {
bindClient(client: Client): void {
const scope = getCurrentScope();
Expand All @@ -48,7 +45,8 @@ export function getCurrentHub(): Hub {
setContext,

getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {
return getClient()?.getIntegrationByName<T>(integration.id) || null;
const client = getClient();
return (client && client.getIntegrationByName<T>(integration.id)) || null;
},

startSession,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
10 changes: 7 additions & 3 deletions packages/opentelemetry/src/asyncContextStrategy.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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';
Expand Down Expand Up @@ -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: () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down