Skip to content

Commit d76126b

Browse files
committed
ref: Avoid carrier for domain ACS
1 parent ac39685 commit d76126b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

packages/node/src/async/domain.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
import * as domain from 'domain';
2-
import type { Carrier } from '@sentry/core';
32
import { getGlobalHub } from '@sentry/core';
43
import { Hub as HubClass } from '@sentry/core';
5-
import { ensureHubOnCarrier, getHubFromCarrier, setAsyncContextStrategy, setHubOnCarrier } from '@sentry/core';
4+
import { setAsyncContextStrategy } from '@sentry/core';
65
import type { Client, Hub, Scope } from '@sentry/types';
76

7+
type DomainWithHub = domain.Domain & {
8+
hub?: Hub;
9+
};
10+
811
function getActiveDomain<T>(): T | undefined {
912
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
1013
return (domain as any).active as T | undefined;
1114
}
1215

1316
function getCurrentDomainHub(): Hub | undefined {
14-
const activeDomain = getActiveDomain<Carrier>();
17+
const activeDomain = getActiveDomain<DomainWithHub>();
1518

1619
// If there's no active domain, just return undefined and the global hub will be used
1720
if (!activeDomain) {
1821
return undefined;
1922
}
2023

21-
ensureHubOnCarrier(activeDomain);
24+
if (activeDomain.hub) {
25+
return activeDomain.hub;
26+
}
2227

23-
return getHubFromCarrier(activeDomain);
28+
activeDomain.hub = getCurrentHub();
29+
return activeDomain.hub;
2430
}
2531

2632
function getCurrentHub(): Hub {
@@ -33,11 +39,11 @@ function withExecutionContext<T>(
3339
isolationScope: Scope,
3440
callback: () => T,
3541
): T {
36-
const local = domain.create() as domain.Domain & Carrier;
42+
const local = domain.create() as DomainWithHub;
3743

3844
// eslint-disable-next-line deprecation/deprecation
3945
const newHub = new HubClass(client, scope, isolationScope);
40-
setHubOnCarrier(local, newHub);
46+
local.hub = newHub;
4147

4248
return local.bind(() => {
4349
return callback();

0 commit comments

Comments
 (0)