File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
packages/browser-utils/src/metrics Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -105,24 +105,32 @@ export function startTrackingWebVitals({ recordClsStandaloneSpans }: StartTracki
105105 */
106106export function startTrackingLongTasks ( ) : void {
107107 addPerformanceInstrumentationHandler ( 'longtask' , ( { entries } ) => {
108- if ( ! getActiveSpan ( ) ) {
108+ const parent = getActiveSpan ( ) ;
109+ if ( ! parent ) {
109110 return ;
110111 }
112+
113+ const { op : parentOp , start_timestamp : parentStartTimestamp } = spanToJSON ( parent ) ;
114+
111115 for ( const entry of entries ) {
112116 const startTime = msToSec ( ( browserPerformanceTimeOrigin as number ) + entry . startTime ) ;
113117 const duration = msToSec ( entry . duration ) ;
114118
115- const span = startInactiveSpan ( {
119+ if ( parentOp === 'navigation' && parentStartTimestamp && startTime < parentStartTimestamp ) {
120+ // Skip adding a span if the long task started before the navigation started.
121+ // `startAndEndSpan` will otherwise adjust the parent's start time to the span's start
122+ // time, potentially skewing the duration of the actual navigation as reported via our
123+ // routing instrumentations
124+ continue ;
125+ }
126+
127+ startAndEndSpan ( parent , startTime , startTime + duration , {
116128 name : 'Main UI thread blocked' ,
117129 op : 'ui.long-task' ,
118- startTime,
119130 attributes : {
120131 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.browser.metrics' ,
121132 } ,
122133 } ) ;
123- if ( span ) {
124- span . end ( startTime + duration ) ;
125- }
126134 }
127135 } ) ;
128136}
You can’t perform that action at this time.
0 commit comments