1
1
import * as domain from 'domain' ;
2
- import type { Carrier } from '@sentry/core' ;
3
2
import { getGlobalHub } from '@sentry/core' ;
4
3
import { Hub as HubClass } from '@sentry/core' ;
5
- import { ensureHubOnCarrier , getHubFromCarrier , setAsyncContextStrategy , setHubOnCarrier } from '@sentry/core' ;
4
+ import { setAsyncContextStrategy } from '@sentry/core' ;
6
5
import type { Client , Hub , Scope } from '@sentry/types' ;
7
6
7
+ type DomainWithHub = domain . Domain & {
8
+ hub ?: Hub ;
9
+ } ;
10
+
8
11
function getActiveDomain < T > ( ) : T | undefined {
9
12
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
10
13
return ( domain as any ) . active as T | undefined ;
11
14
}
12
15
13
16
function getCurrentDomainHub ( ) : Hub | undefined {
14
- const activeDomain = getActiveDomain < Carrier > ( ) ;
17
+ const activeDomain = getActiveDomain < DomainWithHub > ( ) ;
15
18
16
19
// If there's no active domain, just return undefined and the global hub will be used
17
20
if ( ! activeDomain ) {
18
21
return undefined ;
19
22
}
20
23
21
- ensureHubOnCarrier ( activeDomain ) ;
24
+ if ( activeDomain . hub ) {
25
+ return activeDomain . hub ;
26
+ }
22
27
23
- return getHubFromCarrier ( activeDomain ) ;
28
+ activeDomain . hub = getCurrentHub ( ) ;
29
+ return activeDomain . hub ;
24
30
}
25
31
26
32
function getCurrentHub ( ) : Hub {
@@ -33,11 +39,11 @@ function withExecutionContext<T>(
33
39
isolationScope : Scope ,
34
40
callback : ( ) => T ,
35
41
) : T {
36
- const local = domain . create ( ) as domain . Domain & Carrier ;
42
+ const local = domain . create ( ) as DomainWithHub ;
37
43
38
44
// eslint-disable-next-line deprecation/deprecation
39
45
const newHub = new HubClass ( client , scope , isolationScope ) ;
40
- setHubOnCarrier ( local , newHub ) ;
46
+ local . hub = newHub ;
41
47
42
48
return local . bind ( ( ) => {
43
49
return callback ( ) ;
0 commit comments