1
1
import { BrowserClient } from '@sentry/browser' ;
2
2
import { Hub , makeMain } from '@sentry/hub' ;
3
- import { BaggageObj } from '@sentry/types' ;
3
+ import type { BaggageObj , BaseTransportOptions , ClientOptions } from '@sentry/types' ;
4
4
import { getGlobalObject , InstrumentHandlerCallback , InstrumentHandlerType } from '@sentry/utils' ;
5
5
import { JSDOM } from 'jsdom' ;
6
6
@@ -415,7 +415,16 @@ describe('BrowserTracing', () => {
415
415
} ) ;
416
416
} ) ;
417
417
418
- describe ( 'using the data' , ( ) => {
418
+ describe ( 'using the <meta> tag data' , ( ) => {
419
+ beforeEach ( ( ) => {
420
+ hub . getClient ( ) ! . getOptions = ( ) => {
421
+ return {
422
+ release : '1.0.0' ,
423
+ environment : 'production' ,
424
+ } as ClientOptions < BaseTransportOptions > ;
425
+ } ;
426
+ } ) ;
427
+
419
428
it ( 'uses the tracing data for pageload transactions' , ( ) => {
420
429
// make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one
421
430
document . head . innerHTML =
@@ -439,11 +448,34 @@ describe('BrowserTracing', () => {
439
448
expect ( baggage [ 1 ] ) . toEqual ( 'foo=bar' ) ;
440
449
} ) ;
441
450
451
+ it ( 'adds Sentry baggage data to pageload transactions if not present in meta tags' , ( ) => {
452
+ // make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one
453
+ document . head . innerHTML =
454
+ '<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">' +
455
+ '<meta name="baggage" content="foo=bar">' ;
456
+
457
+ // pageload transactions are created as part of the BrowserTracing integration's initialization
458
+ createBrowserTracing ( true ) ;
459
+ const transaction = getActiveTransaction ( hub ) as IdleTransaction ;
460
+ const baggage = transaction . getBaggage ( ) ! ;
461
+
462
+ expect ( transaction ) . toBeDefined ( ) ;
463
+ expect ( transaction . op ) . toBe ( 'pageload' ) ;
464
+ expect ( transaction . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
465
+ expect ( transaction . parentSpanId ) . toEqual ( '1121201211212012' ) ;
466
+ expect ( transaction . sampled ) . toBe ( false ) ;
467
+ expect ( baggage ) . toBeDefined ( ) ;
468
+ expect ( baggage [ 0 ] ) . toBeDefined ( ) ;
469
+ expect ( baggage [ 0 ] ) . toEqual ( { environment : 'production' , release : '1.0.0' } ) ;
470
+ expect ( baggage [ 1 ] ) . toBeDefined ( ) ;
471
+ expect ( baggage [ 1 ] ) . toEqual ( 'foo=bar' ) ;
472
+ } ) ;
473
+
442
474
it ( 'ignores the data for navigation transactions' , ( ) => {
443
475
mockChangeHistory = ( ) => undefined ;
444
476
document . head . innerHTML =
445
477
'<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">' +
446
- '<meta name="baggage" content="sentry-release=2.1.14,foo=bar ">' ;
478
+ '<meta name="baggage" content="sentry-release=2.1.14">' ;
447
479
448
480
createBrowserTracing ( true ) ;
449
481
@@ -455,7 +487,11 @@ describe('BrowserTracing', () => {
455
487
expect ( transaction . op ) . toBe ( 'navigation' ) ;
456
488
expect ( transaction . traceId ) . not . toEqual ( '12312012123120121231201212312012' ) ;
457
489
expect ( transaction . parentSpanId ) . toBeUndefined ( ) ;
458
- expect ( baggage ) . toBeUndefined ( ) ;
490
+ expect ( baggage ) . toBeDefined ( ) ;
491
+ expect ( baggage [ 0 ] ) . toBeDefined ( ) ;
492
+ expect ( baggage [ 0 ] ) . toEqual ( { release : '1.0.0' , environment : 'production' } ) ;
493
+ expect ( baggage [ 1 ] ) . toBeDefined ( ) ;
494
+ expect ( baggage [ 1 ] ) . toEqual ( '' ) ;
459
495
} ) ;
460
496
} ) ;
461
497
} ) ;
0 commit comments