@@ -2,7 +2,7 @@ import * as sentryCore from '@sentry/core';
2
2
import * as sentryHub from '@sentry/hub' ;
3
3
import { Hub } from '@sentry/hub' ;
4
4
import { Transaction } from '@sentry/tracing' ;
5
- import { Runtime } from '@sentry/types' ;
5
+ import { Baggage , Runtime } from '@sentry/types' ;
6
6
import { SentryError } from '@sentry/utils' ;
7
7
import * as http from 'http' ;
8
8
import * as net from 'net' ;
@@ -368,6 +368,41 @@ describe('tracingHandler', () => {
368
368
expect ( transaction . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
369
369
expect ( transaction . parentSpanId ) . toEqual ( '1121201211212012' ) ;
370
370
expect ( transaction . sampled ) . toEqual ( false ) ;
371
+ expect ( transaction . metadata ?. baggage ) . toBeUndefined ( ) ;
372
+ } ) ;
373
+
374
+ it ( "pulls parent's data from tracing and baggage headers on the request" , ( ) => {
375
+ req . headers = {
376
+ 'sentry-trace' : '12312012123120121231201212312012-1121201211212012-0' ,
377
+ baggage : 'sentry-version=1.0,sentry-environment=production' ,
378
+ } ;
379
+
380
+ sentryTracingMiddleware ( req , res , next ) ;
381
+
382
+ const transaction = ( res as any ) . __sentry_transaction ;
383
+
384
+ // since we have no tracesSampler defined, the default behavior (inherit if possible) applies
385
+ expect ( transaction . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
386
+ expect ( transaction . parentSpanId ) . toEqual ( '1121201211212012' ) ;
387
+ expect ( transaction . sampled ) . toEqual ( false ) ;
388
+ expect ( transaction . metadata ?. baggage ) . toBeDefined ( ) ;
389
+ expect ( transaction . metadata ?. baggage ) . toEqual ( [ { version : '1.0' , environment : 'production' } , '' ] as Baggage ) ;
390
+ } ) ;
391
+
392
+ it ( "pulls parent's baggage (sentry + third party entries) headers on the request" , ( ) => {
393
+ req . headers = {
394
+ baggage : 'sentry-version=1.0,sentry-environment=production,dogs=great,cats=boring' ,
395
+ } ;
396
+
397
+ sentryTracingMiddleware ( req , res , next ) ;
398
+
399
+ const transaction = ( res as any ) . __sentry_transaction ;
400
+
401
+ expect ( transaction . metadata ?. baggage ) . toBeDefined ( ) ;
402
+ expect ( transaction . metadata ?. baggage ) . toEqual ( [
403
+ { version : '1.0' , environment : 'production' } ,
404
+ 'dogs=great,cats=boring' ,
405
+ ] as Baggage ) ;
371
406
} ) ;
372
407
373
408
it ( 'extracts request data for sampling context' , ( ) => {
0 commit comments