@@ -11,7 +11,7 @@ import {
11
11
import type { Span } from '@sentry/core' ;
12
12
import { describe , beforeEach , it , expect , beforeAll , afterAll } from 'vitest' ;
13
13
14
- import { _addMeasureSpans , _addResourceSpans } from '../../src/metrics/browserMetrics' ;
14
+ import { _addMeasureSpans , _addNavigationSpans , _addResourceSpans } from '../../src/metrics/browserMetrics' ;
15
15
import { WINDOW } from '../../src/types' ;
16
16
import { TestClient , getDefaultClientOptions } from '../utils/TestClient' ;
17
17
@@ -416,6 +416,188 @@ describe('_addResourceSpans', () => {
416
416
) ;
417
417
} ) ;
418
418
419
+ describe ( '_addNavigationSpans' , ( ) => {
420
+ const pageloadSpan = new SentrySpan ( { op : 'pageload' , name : '/' , sampled : true } ) ;
421
+
422
+ beforeAll ( ( ) => {
423
+ setGlobalLocation ( mockWindowLocation ) ;
424
+ } ) ;
425
+
426
+ afterAll ( ( ) => {
427
+ resetGlobalLocation ( ) ;
428
+ } ) ;
429
+
430
+ beforeEach ( ( ) => {
431
+ getCurrentScope ( ) . clear ( ) ;
432
+ getIsolationScope ( ) . clear ( ) ;
433
+
434
+ const client = new TestClient (
435
+ getDefaultClientOptions ( {
436
+ tracesSampleRate : 1 ,
437
+ } ) ,
438
+ ) ;
439
+ setCurrentClient ( client ) ;
440
+ client . init ( ) ;
441
+ } ) ;
442
+
443
+ it ( 'adds navigation spans based on the navigation performance entry' , ( ) => {
444
+ // entry taken from a real entry via browser dev tools
445
+ const entry : PerformanceNavigationTiming = {
446
+ name : 'https://santry.com/test' ,
447
+ entryType : 'navigation' ,
448
+ startTime : 0 ,
449
+ duration : 546.1000000014901 ,
450
+ initiatorType : 'navigation' ,
451
+ nextHopProtocol : 'h2' ,
452
+ workerStart : 0 ,
453
+ redirectStart : 7.5 ,
454
+ redirectEnd : 20.5 ,
455
+ redirectCount : 2 ,
456
+ fetchStart : 4.9000000059604645 ,
457
+ domainLookupStart : 4.9000000059604645 ,
458
+ domainLookupEnd : 4.9000000059604645 ,
459
+ connectStart : 4.9000000059604645 ,
460
+ secureConnectionStart : 4.9000000059604645 ,
461
+ connectEnd : 4.9000000059604645 ,
462
+ requestStart : 7.9000000059604645 ,
463
+ responseStart : 396.80000000447035 ,
464
+ responseEnd : 416.40000000596046 ,
465
+ transferSize : 14726 ,
466
+ encodedBodySize : 14426 ,
467
+ decodedBodySize : 67232 ,
468
+ responseStatus : 200 ,
469
+ serverTiming : [ ] ,
470
+ unloadEventStart : 0 ,
471
+ unloadEventEnd : 0 ,
472
+ domInteractive : 473.20000000298023 ,
473
+ domContentLoadedEventStart : 480.1000000014901 ,
474
+ domContentLoadedEventEnd : 480.30000000447035 ,
475
+ domComplete : 546 ,
476
+ loadEventStart : 546 ,
477
+ loadEventEnd : 546.1000000014901 ,
478
+ type : 'navigate' ,
479
+ activationStart : 0 ,
480
+ toJSON : ( ) => ( { } ) ,
481
+ } ;
482
+ const spans : Span [ ] = [ ] ;
483
+
484
+ getClient ( ) ?. on ( 'spanEnd' , span => {
485
+ spans . push ( span ) ;
486
+ } ) ;
487
+
488
+ _addNavigationSpans ( pageloadSpan , entry , 999 ) ;
489
+
490
+ const trace_id = pageloadSpan . spanContext ( ) . traceId ;
491
+ const parent_span_id = pageloadSpan . spanContext ( ) . spanId ;
492
+
493
+ expect ( spans ) . toHaveLength ( 9 ) ;
494
+ expect ( spans . map ( spanToJSON ) ) . toEqual (
495
+ expect . arrayContaining ( [
496
+ expect . objectContaining ( {
497
+ data : {
498
+ 'sentry.op' : 'browser.domContentLoadedEvent' ,
499
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
500
+ } ,
501
+ description : 'https://santry.com/test' ,
502
+ op : 'browser.domContentLoadedEvent' ,
503
+ origin : 'auto.ui.browser.metrics' ,
504
+ parent_span_id,
505
+ trace_id,
506
+ } ) ,
507
+ expect . objectContaining ( {
508
+ data : {
509
+ 'sentry.op' : 'browser.loadEvent' ,
510
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
511
+ } ,
512
+ description : 'https://santry.com/test' ,
513
+ op : 'browser.loadEvent' ,
514
+ origin : 'auto.ui.browser.metrics' ,
515
+ parent_span_id,
516
+ trace_id,
517
+ } ) ,
518
+ expect . objectContaining ( {
519
+ data : {
520
+ 'sentry.op' : 'browser.connect' ,
521
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
522
+ } ,
523
+ description : 'https://santry.com/test' ,
524
+ op : 'browser.connect' ,
525
+ origin : 'auto.ui.browser.metrics' ,
526
+ parent_span_id,
527
+ trace_id,
528
+ } ) ,
529
+ expect . objectContaining ( {
530
+ data : {
531
+ 'sentry.op' : 'browser.TLS/SSL' ,
532
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
533
+ } ,
534
+ description : 'https://santry.com/test' ,
535
+ op : 'browser.TLS/SSL' ,
536
+ origin : 'auto.ui.browser.metrics' ,
537
+ parent_span_id,
538
+ trace_id,
539
+ } ) ,
540
+ expect . objectContaining ( {
541
+ data : {
542
+ 'sentry.op' : 'browser.cache' ,
543
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
544
+ } ,
545
+ description : 'https://santry.com/test' ,
546
+ op : 'browser.cache' ,
547
+ origin : 'auto.ui.browser.metrics' ,
548
+ parent_span_id,
549
+ trace_id,
550
+ } ) ,
551
+ expect . objectContaining ( {
552
+ data : {
553
+ 'sentry.op' : 'browser.DNS' ,
554
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
555
+ } ,
556
+ description : 'https://santry.com/test' ,
557
+ op : 'browser.DNS' ,
558
+ origin : 'auto.ui.browser.metrics' ,
559
+ parent_span_id,
560
+ trace_id,
561
+ } ) ,
562
+ expect . objectContaining ( {
563
+ data : {
564
+ 'sentry.op' : 'browser.request' ,
565
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
566
+ } ,
567
+ description : 'https://santry.com/test' ,
568
+ op : 'browser.request' ,
569
+ origin : 'auto.ui.browser.metrics' ,
570
+ parent_span_id,
571
+ trace_id,
572
+ } ) ,
573
+ expect . objectContaining ( {
574
+ data : {
575
+ 'sentry.op' : 'browser.response' ,
576
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
577
+ } ,
578
+ description : 'https://santry.com/test' ,
579
+ op : 'browser.response' ,
580
+ origin : 'auto.ui.browser.metrics' ,
581
+ parent_span_id,
582
+ trace_id,
583
+ } ) ,
584
+ expect . objectContaining ( {
585
+ data : {
586
+ 'http.redirect_count' : 2 ,
587
+ 'sentry.op' : 'browser.redirect' ,
588
+ 'sentry.origin' : 'auto.ui.browser.metrics' ,
589
+ } ,
590
+ description : 'https://santry.com/test' ,
591
+ op : 'browser.redirect' ,
592
+ origin : 'auto.ui.browser.metrics' ,
593
+ parent_span_id,
594
+ trace_id,
595
+ } ) ,
596
+ ] ) ,
597
+ ) ;
598
+ } ) ;
599
+ } ) ;
600
+
419
601
const setGlobalLocation = ( location : Location ) => {
420
602
// @ts -expect-error need to delete this in order to set to new value
421
603
delete WINDOW . location ;
0 commit comments