1
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
2
import {
3
3
captureException ,
4
+ continueTrace ,
4
5
flush ,
5
6
getCurrentHub ,
6
7
hasTracingEnabled ,
@@ -19,7 +20,6 @@ import {
19
20
isThenable ,
20
21
logger ,
21
22
normalize ,
22
- tracingContextFromHeaders ,
23
23
} from '@sentry/utils' ;
24
24
import type * as http from 'http' ;
25
25
@@ -57,35 +57,31 @@ export function tracingHandler(): (
57
57
58
58
const sentryTrace = req . headers && isString ( req . headers [ 'sentry-trace' ] ) ? req . headers [ 'sentry-trace' ] : undefined ;
59
59
const baggage = req . headers ?. baggage ;
60
- const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders (
61
- sentryTrace ,
62
- baggage ,
63
- ) ;
64
- hub . getScope ( ) . setPropagationContext ( propagationContext ) ;
65
-
66
60
if ( ! hasTracingEnabled ( options ) ) {
67
61
return next ( ) ;
68
62
}
69
63
70
64
const [ name , source ] = extractPathForTransaction ( req , { path : true , method : true } ) ;
71
- const transaction = startTransaction (
72
- {
73
- name,
74
- op : 'http.server' ,
75
- origin : 'auto.http.node.tracingHandler' ,
76
- ...traceparentData ,
77
- metadata : {
78
- dynamicSamplingContext : traceparentData && ! dynamicSamplingContext ? { } : dynamicSamplingContext ,
79
- // The request should already have been stored in `scope.sdkProcessingMetadata` (which will become
80
- // `event.sdkProcessingMetadata` the same way the metadata here will) by `sentryRequestMiddleware`, but on the
81
- // off chance someone is using `sentryTracingMiddleware` without `sentryRequestMiddleware`, it doesn't hurt to
82
- // be sure
83
- request : req ,
84
- source,
65
+ const transaction = continueTrace ( { sentryTrace, baggage } , ctx =>
66
+ startTransaction (
67
+ {
68
+ name,
69
+ op : 'http.server' ,
70
+ origin : 'auto.http.node.tracingHandler' ,
71
+ ...ctx ,
72
+ metadata : {
73
+ ...ctx . metadata ,
74
+ // The request should already have been stored in `scope.sdkProcessingMetadata` (which will become
75
+ // `event.sdkProcessingMetadata` the same way the metadata here will) by `sentryRequestMiddleware`, but on the
76
+ // off chance someone is using `sentryTracingMiddleware` without `sentryRequestMiddleware`, it doesn't hurt to
77
+ // be sure
78
+ request : req ,
79
+ source,
80
+ } ,
85
81
} ,
86
- } ,
87
- // extra context passed to the tracesSampler
88
- { request : extractRequestData ( req ) } ,
82
+ // extra context passed to the tracesSampler
83
+ { request : extractRequestData ( req ) } ,
84
+ ) ,
89
85
) ;
90
86
91
87
// We put the transaction on the scope so users can attach children to it
0 commit comments