@@ -3,7 +3,7 @@ import type { Scope } from '@sentry/node';
3
3
import * as Sentry from '@sentry/node' ;
4
4
import { captureException , captureMessage , flush , getCurrentHub , withScope } from '@sentry/node' ;
5
5
import type { Integration } from '@sentry/types' ;
6
- import { baggageHeaderToDynamicSamplingContext , extractTraceparentData , isString , logger } from '@sentry/utils' ;
6
+ import { isString , logger , tracingContextFromHeaders } from '@sentry/utils' ;
7
7
// NOTE: I have no idea how to fix this right now, and don't want to waste more time, as it builds just fine — Kamil
8
8
// eslint-disable-next-line import/no-unresolved
9
9
import type { Context , Handler } from 'aws-lambda' ;
@@ -274,17 +274,20 @@ export function wrapHandler<TEvent, TResult>(
274
274
} , timeoutWarningDelay ) as unknown as NodeJS . Timeout ;
275
275
}
276
276
277
- // Applying `sentry-trace` to context
278
- let traceparentData ;
279
- const eventWithHeaders = event as { headers ?: { [ key : string ] : string } } ;
280
- if ( eventWithHeaders . headers && isString ( eventWithHeaders . headers [ 'sentry-trace' ] ) ) {
281
- traceparentData = extractTraceparentData ( eventWithHeaders . headers [ 'sentry-trace' ] ) ;
282
- }
277
+ const hub = getCurrentHub ( ) ;
283
278
284
- const baggageHeader = eventWithHeaders . headers && eventWithHeaders . headers . baggage ;
285
- const dynamicSamplingContext = baggageHeaderToDynamicSamplingContext ( baggageHeader ) ;
279
+ const eventWithHeaders = event as { headers ?: { [ key : string ] : string } } ;
286
280
287
- const hub = getCurrentHub ( ) ;
281
+ const sentryTrace =
282
+ eventWithHeaders . headers && isString ( eventWithHeaders . headers [ 'sentry-trace' ] )
283
+ ? eventWithHeaders . headers [ 'sentry-trace' ]
284
+ : undefined ;
285
+ const baggage = eventWithHeaders . headers ?. baggage ;
286
+ const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders (
287
+ sentryTrace ,
288
+ baggage ,
289
+ ) ;
290
+ hub . getScope ( ) . setPropagationContext ( propagationContext ) ;
288
291
289
292
const transaction = hub . startTransaction ( {
290
293
name : context . functionName ,
0 commit comments