@@ -453,3 +453,44 @@ sentryTest("doesn't send further CLS after the first page hide", async ({ getLoc
453
453
// a timeout or something similar.
454
454
await navigationTxnPromise ;
455
455
} ) ;
456
+
457
+ sentryTest ( 'CLS span timestamps are set correctly' , async ( { getLocalTestPath, page } ) => {
458
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
459
+
460
+ const eventData = await getFirstSentryEnvelopeRequest < SentryEvent > ( page , url ) ;
461
+
462
+ expect ( eventData . type ) . toBe ( 'transaction' ) ;
463
+ expect ( eventData . contexts ?. trace ?. op ) . toBe ( 'pageload' ) ;
464
+ expect ( eventData . timestamp ) . toBeDefined ( ) ;
465
+
466
+ const pageloadEndTimestamp = eventData . timestamp ! ;
467
+
468
+ const spanEnvelopePromise = getMultipleSentryEnvelopeRequests < SpanEnvelope > (
469
+ page ,
470
+ 1 ,
471
+ { envelopeType : 'span' } ,
472
+ properFullEnvelopeRequestParser ,
473
+ ) ;
474
+
475
+ await triggerAndWaitForLayoutShift ( page ) ;
476
+
477
+ await hidePage ( page ) ;
478
+
479
+ const spanEnvelope = ( await spanEnvelopePromise ) [ 0 ] ;
480
+ const spanEnvelopeItem = spanEnvelope [ 1 ] [ 0 ] [ 1 ] ;
481
+
482
+ expect ( spanEnvelopeItem . start_timestamp ) . toBeDefined ( ) ;
483
+ expect ( spanEnvelopeItem . timestamp ) . toBeDefined ( ) ;
484
+
485
+ const clsSpanStartTimestamp = spanEnvelopeItem . start_timestamp ! ;
486
+ const clsSpanEndTimestamp = spanEnvelopeItem . timestamp ! ;
487
+
488
+ // CLS performance entries have no duration ==> start and end timestamp should be the same
489
+ expect ( clsSpanStartTimestamp ) . toEqual ( clsSpanEndTimestamp ) ;
490
+
491
+ // We don't really care that they are very close together but rather about the order of magnitude
492
+ // Previously, we had a bug where the timestamps would be significantly off (by multiple hours)
493
+ // so we only ensure that this bug is fixed. 60 seconds should be more than enough.
494
+ expect ( clsSpanStartTimestamp - pageloadEndTimestamp ) . toBeLessThan ( 60 ) ;
495
+ expect ( clsSpanStartTimestamp ) . toBeGreaterThan ( pageloadEndTimestamp ) ;
496
+ } ) ;
0 commit comments