@@ -372,21 +372,27 @@ function _addPerformanceNavigationTiming(
372
372
/** Create request and response related spans */
373
373
// eslint-disable-next-line @typescript-eslint/no-explicit-any
374
374
function _addRequest ( transaction : Transaction , entry : Record < string , any > , timeOrigin : number ) : void {
375
- _startChild ( transaction , {
376
- op : 'browser' ,
377
- origin : 'auto.browser.browser.metrics' ,
378
- description : 'request' ,
379
- startTimestamp : timeOrigin + msToSec ( entry . requestStart as number ) ,
380
- endTimestamp : timeOrigin + msToSec ( entry . responseEnd as number ) ,
381
- } ) ;
375
+ if ( entry . responseEnd ) {
376
+ // It is possible that we are collecting these metrics when the page hasn't finished loading yet, for example when the HTML slowly streams in.
377
+ // In this case, ie. when the document request hasn't finished yet, `entry.responseEnd` will be 0.
378
+ // In order not to produce faulty spans, where the end timestamp is before the start timestamp, we will only collect
379
+ // these spans when the responseEnd value is available. The backend (Relay) would drop the entire transaction if it contained faulty spans.
380
+ _startChild ( transaction , {
381
+ op : 'browser' ,
382
+ origin : 'auto.browser.browser.metrics' ,
383
+ description : 'request' ,
384
+ startTimestamp : timeOrigin + msToSec ( entry . requestStart as number ) ,
385
+ endTimestamp : timeOrigin + msToSec ( entry . responseEnd as number ) ,
386
+ } ) ;
382
387
383
- _startChild ( transaction , {
384
- op : 'browser' ,
385
- origin : 'auto.browser.browser.metrics' ,
386
- description : 'response' ,
387
- startTimestamp : timeOrigin + msToSec ( entry . responseStart as number ) ,
388
- endTimestamp : timeOrigin + msToSec ( entry . responseEnd as number ) ,
389
- } ) ;
388
+ _startChild ( transaction , {
389
+ op : 'browser' ,
390
+ origin : 'auto.browser.browser.metrics' ,
391
+ description : 'response' ,
392
+ startTimestamp : timeOrigin + msToSec ( entry . responseStart as number ) ,
393
+ endTimestamp : timeOrigin + msToSec ( entry . responseEnd as number ) ,
394
+ } ) ;
395
+ }
390
396
}
391
397
392
398
export interface ResourceEntry extends Record < string , unknown > {
0 commit comments