Skip to content

Commit ee5bc8d

Browse files
committed
feat(core): Remove getCurrentHub from AsyncContextStrategy
1 parent f6a3e02 commit ee5bc8d

File tree

5 files changed

+6
-76
lines changed

5 files changed

+6
-76
lines changed

packages/core/src/asyncContext.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Hub, Integration } from '@sentry/types';
1+
import type { Integration } from '@sentry/types';
22
import type { Scope } from '@sentry/types';
33
import { GLOBAL_OBJ } from '@sentry/utils';
44
import type { startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan } from './tracing/trace';
@@ -10,12 +10,6 @@ import type { getActiveSpan } from './utils/spanUtils';
1010
* Strategy used to track async context.
1111
*/
1212
export interface AsyncContextStrategy {
13-
/**
14-
* Gets the currently active hub.
15-
*/
16-
// eslint-disable-next-line deprecation/deprecation
17-
getCurrentHub: () => Hub;
18-
1913
/**
2014
* Fork the isolation scope inside of the provided callback.
2115
*/

packages/core/src/hub.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type { AsyncContextStrategy, Carrier } from './asyncContext';
2424
import { getMainCarrier, getSentryCarrier } from './asyncContext';
2525
import { DEFAULT_ENVIRONMENT } from './constants';
2626
import { DEBUG_BUILD } from './debug-build';
27+
import { getCurrentHubShim } from './getCurrentHubShim';
2728
import { Scope } from './scope';
2829
import { closeSession, makeSession, updateSession } from './session';
2930
import { SDK_VERSION } from './version';
@@ -506,13 +507,7 @@ export class Hub implements HubInterface {
506507
* @deprecated Use the respective replacement method directly instead.
507508
*/
508509
// eslint-disable-next-line deprecation/deprecation
509-
export function getCurrentHub(): HubInterface {
510-
// Get main carrier (global for every environment)
511-
const carrier = getMainCarrier();
512-
513-
const acs = getAsyncContextStrategy(carrier);
514-
return acs.getCurrentHub() || getGlobalHub();
515-
}
510+
export const getCurrentHub = getCurrentHubShim;
516511

517512
/** Get the default current scope. */
518513
export function getDefaultCurrentScope(): Scope {
@@ -586,7 +581,6 @@ function withIsolationScope<T>(callback: (isolationScope: ScopeInterface) => T):
586581
/* eslint-disable deprecation/deprecation */
587582
function getHubStackAsyncContextStrategy(): AsyncContextStrategy {
588583
return {
589-
getCurrentHub: getGlobalHub,
590584
withIsolationScope,
591585
withScope,
592586
withSetScope,

packages/core/src/sdk.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import type { Client, ClientOptions, Hub as HubInterface } from '@sentry/types';
1+
import type { Client, ClientOptions } from '@sentry/types';
22
import { consoleSandbox, logger } from '@sentry/utils';
33
import { getCurrentScope } from './currentScopes';
44

55
import { DEBUG_BUILD } from './debug-build';
6-
import type { Hub } from './hub';
7-
import { getCurrentHub } from './hub';
86

97
/** A class object that can instantiate Client objects. */
108
export type ClientClass<F extends Client, O extends ClientOptions> = new (options: O) => F;
@@ -44,19 +42,4 @@ export function initAndBind<F extends Client, O extends ClientOptions>(
4442
*/
4543
export function setCurrentClient(client: Client): void {
4644
getCurrentScope().setClient(client);
47-
48-
// is there a hub too?
49-
// eslint-disable-next-line deprecation/deprecation
50-
const hub = getCurrentHub();
51-
if (isHubClass(hub)) {
52-
// eslint-disable-next-line deprecation/deprecation
53-
const top = hub.getStackTop();
54-
top.client = client;
55-
}
56-
}
57-
58-
// eslint-disable-next-line deprecation/deprecation
59-
function isHubClass(hub: HubInterface): hub is Hub {
60-
// eslint-disable-next-line deprecation/deprecation
61-
return !!(hub as Hub).getStackTop;
6245
}

packages/opentelemetry/src/asyncContextStrategy.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,6 @@ export function setOpenTelemetryContextAsyncContextStrategy(): void {
4040
};
4141
}
4242

43-
// eslint-disable-next-line deprecation/deprecation
44-
function getCurrentHub(): Hub {
45-
// eslint-disable-next-line deprecation/deprecation
46-
const hub = getCurrentHubShim();
47-
return {
48-
...hub,
49-
getScope: () => {
50-
const scopes = getScopes();
51-
return scopes.scope;
52-
},
53-
getIsolationScope: () => {
54-
const scopes = getScopes();
55-
return scopes.isolationScope;
56-
},
57-
};
58-
}
59-
6043
function withScope<T>(callback: (scope: Scope) => T): T {
6144
const ctx = api.context.active();
6245

@@ -114,7 +97,6 @@ export function setOpenTelemetryContextAsyncContextStrategy(): void {
11497
}
11598

11699
setAsyncContextStrategy({
117-
getCurrentHub,
118100
withScope,
119101
withSetScope,
120102
withSetIsolationScope,

packages/vercel-edge/src/async.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import {
2-
getCurrentHubShim,
3-
getDefaultCurrentScope,
4-
getDefaultIsolationScope,
5-
setAsyncContextStrategy,
6-
} from '@sentry/core';
7-
import type { Hub, Scope } from '@sentry/types';
1+
import { getDefaultCurrentScope, getDefaultIsolationScope, setAsyncContextStrategy } from '@sentry/core';
2+
import type { Scope } from '@sentry/types';
83
import { GLOBAL_OBJ, logger } from '@sentry/utils';
94

105
import { DEBUG_BUILD } from './debug-build';
@@ -51,23 +46,6 @@ export function setAsyncLocalStorageAsyncContextStrategy(): void {
5146
};
5247
}
5348

54-
// eslint-disable-next-line deprecation/deprecation
55-
function getCurrentHub(): Hub {
56-
// eslint-disable-next-line deprecation/deprecation
57-
const hub = getCurrentHubShim();
58-
return {
59-
...hub,
60-
getScope: () => {
61-
const scopes = getScopes();
62-
return scopes.scope;
63-
},
64-
getIsolationScope: () => {
65-
const scopes = getScopes();
66-
return scopes.isolationScope;
67-
},
68-
};
69-
}
70-
7149
function withScope<T>(callback: (scope: Scope) => T): T {
7250
const scope = getScopes().scope.clone();
7351
const isolationScope = getScopes().isolationScope;
@@ -99,7 +77,6 @@ export function setAsyncLocalStorageAsyncContextStrategy(): void {
9977
}
10078

10179
setAsyncContextStrategy({
102-
getCurrentHub,
10380
withScope,
10481
withSetScope,
10582
withIsolationScope,

0 commit comments

Comments
 (0)