@@ -581,7 +581,7 @@ export class Tracing implements Integration {
581
581
582
582
// tslint:disable-next-line: completed-docs
583
583
function addPerformanceNavigationTiming ( parent : Span , entry : { [ key : string ] : number } , event : string ) : void {
584
- parent . startChild ( {
584
+ _startChild ( parent , {
585
585
description : event ,
586
586
endTimestamp : timeOrigin + Tracing . _msToSec ( entry [ `${ event } End` ] ) ,
587
587
op : 'browser' ,
@@ -591,14 +591,14 @@ export class Tracing implements Integration {
591
591
592
592
// tslint:disable-next-line: completed-docs
593
593
function addRequest ( parent : Span , entry : { [ key : string ] : number } ) : void {
594
- parent . startChild ( {
594
+ _startChild ( parent , {
595
595
description : 'request' ,
596
596
endTimestamp : timeOrigin + Tracing . _msToSec ( entry . responseEnd ) ,
597
597
op : 'browser' ,
598
598
startTimestamp : timeOrigin + Tracing . _msToSec ( entry . requestStart ) ,
599
599
} ) ;
600
600
601
- parent . startChild ( {
601
+ _startChild ( parent , {
602
602
description : 'response' ,
603
603
endTimestamp : timeOrigin + Tracing . _msToSec ( entry . responseEnd ) ,
604
604
op : 'browser' ,
@@ -648,12 +648,12 @@ export class Tracing implements Integration {
648
648
case 'mark' :
649
649
case 'paint' :
650
650
case 'measure' :
651
- const mark = transactionSpan . startChild ( {
651
+ const mark = _startChild ( transactionSpan , {
652
652
description : entry . name ,
653
+ endTimestamp : timeOrigin + startTime + duration ,
653
654
op : entry . entryType ,
655
+ startTimestamp : timeOrigin + startTime ,
654
656
} ) ;
655
- mark . startTimestamp = timeOrigin + startTime ;
656
- mark . endTimestamp = mark . startTimestamp + duration ;
657
657
if ( tracingInitMarkStartTime === undefined && entry . name === 'sentry-tracing-init' ) {
658
658
tracingInitMarkStartTime = mark . startTimestamp ;
659
659
}
@@ -671,12 +671,12 @@ export class Tracing implements Integration {
671
671
} ) ;
672
672
}
673
673
} else {
674
- const resource = transactionSpan . startChild ( {
674
+ const resource = _startChild ( transactionSpan , {
675
675
description : `${ entry . initiatorType } ${ resourceName } ` ,
676
+ endTimestamp : timeOrigin + startTime + duration ,
676
677
op : `resource` ,
678
+ startTimestamp : timeOrigin + startTime ,
677
679
} ) ;
678
- resource . startTimestamp = timeOrigin + startTime ;
679
- resource . endTimestamp = resource . startTimestamp + duration ;
680
680
// We remember the entry script end time to calculate the difference to the first init mark
681
681
if ( entryScriptStartEndTime === undefined && ( entryScriptSrc || '' ) . indexOf ( resourceName ) > - 1 ) {
682
682
entryScriptStartEndTime = resource . endTimestamp ;
@@ -689,7 +689,7 @@ export class Tracing implements Integration {
689
689
} ) ;
690
690
691
691
if ( entryScriptStartEndTime !== undefined && tracingInitMarkStartTime !== undefined ) {
692
- transactionSpan . startChild ( {
692
+ _startChild ( transactionSpan , {
693
693
description : 'evaluation' ,
694
694
endTimestamp : tracingInitMarkStartTime ,
695
695
op : `script` ,
@@ -1054,3 +1054,19 @@ function historyCallback(_: { [key: string]: any }): void {
1054
1054
} ) ;
1055
1055
}
1056
1056
}
1057
+
1058
+ /**
1059
+ * Helper function to start child on transactions. This function will make sure that the transaction will
1060
+ * will use the start timestamp of the created child span if it is earlier than the transactions actual
1061
+ * start timestamp.
1062
+ */
1063
+ export function _startChild ( parent : Span , { startTimestamp, ...ctx } : SpanContext ) : Span {
1064
+ if ( startTimestamp && parent . startTimestamp > startTimestamp ) {
1065
+ parent . startTimestamp = startTimestamp ;
1066
+ }
1067
+
1068
+ return parent . startChild ( {
1069
+ startTimestamp,
1070
+ ...ctx ,
1071
+ } ) ;
1072
+ }
0 commit comments