File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { NODE_VERSION } from '../nodeVersion' ;
2
+ import { setDomainAsyncContextStrategy } from './domain' ;
3
+ import { setHooksAsyncContextStrategy } from './hooks' ;
4
+
5
+ /**
6
+ * Sets the correct async context strategy for Node.js
7
+ *
8
+ * Node.js >= 14 uses AsyncLocalStorage
9
+ * Node.js < 14 uses domains
10
+ */
11
+ export function setNodeAsyncContextStrategy ( ) : void {
12
+ if ( NODE_VERSION . major && NODE_VERSION . major >= 14 ) {
13
+ setHooksAsyncContextStrategy ( ) ;
14
+ } else {
15
+ setDomainAsyncContextStrategy ( ) ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import {
15
15
stackParserFromStackParserOptions ,
16
16
} from '@sentry/utils' ;
17
17
18
- import { setDomainAsyncContextStrategy } from './async/domain ' ;
18
+ import { setNodeAsyncContextStrategy } from './async' ;
19
19
import { NodeClient } from './client' ;
20
20
import {
21
21
Console ,
@@ -111,7 +111,7 @@ export const defaultIntegrations = [
111
111
export function init ( options : NodeOptions = { } ) : void {
112
112
const carrier = getMainCarrier ( ) ;
113
113
114
- setDomainAsyncContextStrategy ( ) ;
114
+ setNodeAsyncContextStrategy ( ) ;
115
115
116
116
const autoloadedIntegrations = carrier . __SENTRY__ ?. integrations || [ ] ;
117
117
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
12
12
init ,
13
13
NodeClient ,
14
14
} from '../src' ;
15
- import { setDomainAsyncContextStrategy } from '../src/async/domain ' ;
15
+ import { setNodeAsyncContextStrategy } from '../src/async' ;
16
16
import { ContextLines , LinkedErrors } from '../src/integrations' ;
17
17
import { defaultStackParser } from '../src/sdk' ;
18
18
import type { NodeClientOptions } from '../src/types' ;
@@ -288,7 +288,7 @@ describe('SentryNode', () => {
288
288
} ,
289
289
dsn,
290
290
} ) ;
291
- setDomainAsyncContextStrategy ( ) ;
291
+ setNodeAsyncContextStrategy ( ) ;
292
292
const client = new NodeClient ( options ) ;
293
293
294
294
runWithAsyncContext ( hub => {
You can’t perform that action at this time.
0 commit comments