@@ -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
}
@@ -663,12 +663,12 @@ export class Tracing implements Integration {
663
663
// we already instrument based on fetch and xhr, so we don't need to
664
664
// duplicate spans here.
665
665
if ( entry . initiatorType !== 'xmlhttprequest' && entry . initiatorType !== 'fetch' ) {
666
- const resource = transactionSpan . startChild ( {
666
+ const resource = _startChild ( transactionSpan , {
667
667
description : `${ entry . initiatorType } ${ resourceName } ` ,
668
+ endTimestamp : timeOrigin + startTime + duration ,
668
669
op : `resource` ,
670
+ startTimestamp : timeOrigin + startTime ,
669
671
} ) ;
670
- resource . startTimestamp = timeOrigin + startTime ;
671
- resource . endTimestamp = resource . startTimestamp + duration ;
672
672
// We remember the entry script end time to calculate the difference to the first init mark
673
673
if ( entryScriptStartEndTime === undefined && ( entryScriptSrc || '' ) . indexOf ( resourceName ) > - 1 ) {
674
674
entryScriptStartEndTime = resource . endTimestamp ;
@@ -681,7 +681,7 @@ export class Tracing implements Integration {
681
681
} ) ;
682
682
683
683
if ( entryScriptStartEndTime !== undefined && tracingInitMarkStartTime !== undefined ) {
684
- transactionSpan . startChild ( {
684
+ _startChild ( transactionSpan , {
685
685
description : 'evaluation' ,
686
686
endTimestamp : tracingInitMarkStartTime ,
687
687
op : `script` ,
@@ -1046,3 +1046,19 @@ function historyCallback(_: { [key: string]: any }): void {
1046
1046
} ) ;
1047
1047
}
1048
1048
}
1049
+
1050
+ /**
1051
+ * Helper function to start child on transactions. This function will make sure that the transaction will
1052
+ * will use the start timestamp of the created child span if it is earlier than the transactions actual
1053
+ * start timestamp.
1054
+ */
1055
+ export function _startChild ( parent : Span , { startTimestamp, ...ctx } : SpanContext ) : Span {
1056
+ if ( startTimestamp && parent . startTimestamp > startTimestamp ) {
1057
+ parent . startTimestamp = startTimestamp ;
1058
+ }
1059
+
1060
+ return parent . startChild ( {
1061
+ startTimestamp,
1062
+ ...ctx ,
1063
+ } ) ;
1064
+ }
0 commit comments