@@ -4,37 +4,19 @@ import { AsyncLocalStorage } from 'node:async_hooks';
44import { getRootSpan , spanIsIgnored , type TracingChannelBinding } from '@sentry/core' ;
55import { SENTRY_TRACE_STATE_CHILD_IGNORED } from './constants' ;
66
7- export function setNodeOpenTelemetryContextAsyncContextStrategy ( options ?: {
8- asyncLocalStorage ?: AsyncLocalStorage < api . Context > ;
9- } ) : void {
7+ export function setNodeOpenTelemetryContextAsyncContextStrategy ( ) : void {
8+ const asyncLocalStorage = new AsyncLocalStorage < api . Context > ( ) ;
9+
1010 setOpenTelemetryContextAsyncContextStrategy ( {
11- getTracingChannelBinding : options ?. asyncLocalStorage
12- ? getAsyncLocalStorageFactory ( options . asyncLocalStorage )
13- : getDefaultAsyncLocalStorageFactory ( ) ,
11+ getTracingChannelBinding : ( ) => {
12+ return {
13+ asyncLocalStorage,
14+ getStoreWithActiveSpan,
15+ } satisfies TracingChannelBinding ;
16+ } ,
1417 } ) ;
1518}
1619
17- /**
18- * In the default case, we build the local storage instance ourselves here.
19- * The default asyncLocalStorageContextManager will then use this internally.
20- */
21- function getDefaultAsyncLocalStorageFactory ( ) : ( ) => TracingChannelBinding {
22- const defaultAsyncLocalStorage = new AsyncLocalStorage < api . Context > ( ) ;
23- return getAsyncLocalStorageFactory ( defaultAsyncLocalStorage ) ;
24- }
25-
26- /**
27- * Build the tracing channel binding factory for the given async local storage instance.
28- */
29- function getAsyncLocalStorageFactory ( asyncLocalStorage : AsyncLocalStorage < api . Context > ) : ( ) => TracingChannelBinding {
30- return ( ) => {
31- return {
32- asyncLocalStorage,
33- getStoreWithActiveSpan,
34- } satisfies TracingChannelBinding ;
35- } ;
36- }
37-
3820function getStoreWithActiveSpan ( span : Parameters < TracingChannelBinding [ 'getStoreWithActiveSpan' ] > [ 0 ] ) : api . Context {
3921 const activeContext = api . context . active ( ) ;
4022
0 commit comments