@@ -19,6 +19,10 @@ const originalHttpGet = http.get;
1919const originalHttpRequest = http . request ;
2020
2121describe ( 'tracing' , ( ) => {
22+ afterEach ( ( ) => {
23+ sentryCore . getCurrentHub ( ) . getScope ( ) . setSpan ( undefined ) ;
24+ } ) ;
25+
2226 function createTransactionOnScope (
2327 customOptions : Partial < NodeClientOptions > = { } ,
2428 customContext ?: Partial < TransactionContext > ,
@@ -178,21 +182,39 @@ describe('tracing', () => {
178182 ] ) ;
179183 } ) ;
180184
185+ it ( "doesn't attach baggage headers if already defined" , ( ) => {
186+ nock ( 'http://dogs.are.great' ) . get ( '/' ) . reply ( 200 ) ;
187+
188+ createTransactionOnScope ( ) ;
189+
190+ const request = http . get ( {
191+ host : 'http://dogs.are.great/' ,
192+ headers : {
193+ 'sentry-trace' : '12312012123120121231201212312012-1231201212312012-0' ,
194+ baggage : 'sentry-environment=production,sentry-trace_id=12312012123120121231201212312012' ,
195+ } ,
196+ } ) ;
197+ const baggage = request . getHeader ( 'baggage' ) ;
198+ expect ( baggage ) . toEqual ( 'sentry-environment=production,sentry-trace_id=12312012123120121231201212312012' ) ;
199+ } ) ;
200+
181201 it ( 'generates and uses propagation context to attach baggage and sentry-trace header' , async ( ) => {
182202 nock ( 'http://dogs.are.great' ) . get ( '/' ) . reply ( 200 ) ;
183203
204+ const { traceId } = sentryCore . getCurrentHub ( ) . getScope ( ) . getPropagationContext ( ) ;
205+
184206 const request = http . get ( 'http://dogs.are.great/' ) ;
185207 const sentryTraceHeader = request . getHeader ( 'sentry-trace' ) as string ;
186208 const baggageHeader = request . getHeader ( 'baggage' ) as string ;
187209
188210 const parts = sentryTraceHeader . split ( '-' ) ;
189211 expect ( parts . length ) . toEqual ( 3 ) ;
190- expect ( parts [ 0 ] ) . toEqual ( '12312012123120121231201212312012' ) ;
212+ expect ( parts [ 0 ] ) . toEqual ( traceId ) ;
191213 expect ( parts [ 1 ] ) . toEqual ( expect . any ( String ) ) ;
192- expect ( parts [ 2 ] ) . toEqual ( '1 ' ) ;
214+ expect ( parts [ 2 ] ) . toEqual ( '0 ' ) ;
193215
194216 expect ( baggageHeader ) . toEqual (
195- ' sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=12312012123120121231201212312012,sentry-sample_rate=1,sentry-sampled=true' ,
217+ ` sentry-environment=production,sentry-release=1.0.0,sentry-user_segment=segmentA,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=${ traceId } ` ,
196218 ) ;
197219 } ) ;
198220
0 commit comments