@@ -95,19 +95,6 @@ interface Activity {
9595const global = getGlobalObject < Window > ( ) ;
9696const defaultTracingOrigins = [ 'localhost' , / ^ \/ / ] ;
9797
98- if ( global . performance ) {
99- // Polyfill for performance.timeOrigin.
100- //
101- // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin
102- // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing.
103- // tslint:disable-next-line:strict-type-predicates
104- if ( performance . timeOrigin === undefined ) {
105- // @ts -ignore
106- // tslint:disable-next-line:deprecation
107- performance . timeOrigin = performance . timing . navigationStart ;
108- }
109- }
110-
11198/**
11299 * Tracing Integration
113100 */
@@ -297,13 +284,20 @@ export class Tracing implements Integration {
297284 document . addEventListener ( 'visibilitychange' , ( ) => {
298285 if ( document . hidden && Tracing . _activeTransaction ) {
299286 logger . log ( '[Tracing] Discarded active transaction incl. activities since tab moved to the background' ) ;
300- Tracing . _activeTransaction = undefined ;
301- Tracing . _activities = { } ;
287+ Tracing . _resetActiveTransaction ( ) ;
302288 }
303289 } ) ;
304290 }
305291 }
306292
293+ /**
294+ * Unsets the current active transaction + activities
295+ */
296+ private static _resetActiveTransaction ( ) : void {
297+ Tracing . _activeTransaction = undefined ;
298+ Tracing . _activities = { } ;
299+ }
300+
307301 /**
308302 * Registers to History API to detect navigation changes
309303 */
@@ -415,7 +409,6 @@ export class Tracing implements Integration {
415409 ) ;
416410
417411 Tracing . _activeTransaction = span ;
418- Tracing . _addOffsetToSpan ( span as SpanClass ) ;
419412
420413 // We need to do this workaround here and not use configureScope
421414 // Reason being at the time we start the inital transaction we do not have a client bound on the hub yet
@@ -460,6 +453,7 @@ export class Tracing implements Integration {
460453 logger . log ( '[Tracing] finishIdleTransaction' , active . transaction ) ;
461454 // true = use timestamp of last span
462455 active . finish ( true ) ;
456+ Tracing . _resetActiveTransaction ( ) ;
463457 }
464458 }
465459
@@ -542,6 +536,11 @@ export class Tracing implements Integration {
542536 const startTime = Tracing . _msToSec ( entry . startTime as number ) ;
543537 const duration = Tracing . _msToSec ( entry . duration as number ) ;
544538
539+ if ( transactionSpan . op === 'navigation' && timeOrigin + startTime < transactionSpan . startTimestamp ) {
540+ logger . log ( '[Tracing] Discarded performance entry because of navigation' ) ;
541+ return ;
542+ }
543+
545544 switch ( entry . entryType ) {
546545 case 'navigation' :
547546 addPerformanceNavigationTiming ( transactionSpan , entry , 'unloadEvent' ) ;
@@ -630,18 +629,6 @@ export class Tracing implements Integration {
630629 }
631630 }
632631
633- /**
634- * Adds offset to the span
635- *
636- * @param measureName name of the performance measure
637- * @param span Span to add data.offset to
638- */
639- private static _addOffsetToSpan ( span : SpanClass ) : void {
640- if ( global . performance ) {
641- span . setData ( 'offset' , Tracing . _msToSec ( performance . now ( ) ) ) ;
642- }
643- }
644-
645632 /**
646633 * Converts from milliseconds to seconds
647634 * @param time time in ms
@@ -681,7 +668,6 @@ export class Tracing implements Integration {
681668 const hub = _getCurrentHub ( ) ;
682669 if ( hub ) {
683670 const span = hub . startSpan ( spanContext ) ;
684- Tracing . _addOffsetToSpan ( span as SpanClass ) ;
685671 Tracing . _activities [ Tracing . _currentIndex ] = {
686672 name,
687673 span,
@@ -738,18 +724,6 @@ export class Tracing implements Integration {
738724 } ) ;
739725 }
740726 span . finish ( ) ;
741- // If there is an offset in data, update timestamps accordingly
742- if (
743- global . performance &&
744- span . data &&
745- typeof span . data . offset === 'number' &&
746- typeof span . timestamp === 'number'
747- ) {
748- const timeOrigin = Tracing . _msToSec ( performance . timeOrigin ) ;
749- const duration = span . timestamp - span . startTimestamp ;
750- span . startTimestamp = timeOrigin + span . data . offset ;
751- span . timestamp = timeOrigin + duration ;
752- }
753727 }
754728 // tslint:disable-next-line: no-dynamic-delete
755729 delete Tracing . _activities [ id ] ;
0 commit comments