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
105
105
*/
106
106
export function startTrackingLongTasks ( ) : void {
107
107
addPerformanceInstrumentationHandler ( 'longtask' , ( { entries } ) => {
108
- if ( ! getActiveSpan ( ) ) {
108
+ const parent = getActiveSpan ( ) ;
109
+ if ( ! parent ) {
109
110
return ;
110
111
}
112
+
113
+ const { op : parentOp , start_timestamp : parentStartTimestamp } = spanToJSON ( parent ) ;
114
+
111
115
for ( const entry of entries ) {
112
116
const startTime = msToSec ( ( browserPerformanceTimeOrigin as number ) + entry . startTime ) ;
113
117
const duration = msToSec ( entry . duration ) ;
114
118
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 , {
116
128
name : 'Main UI thread blocked' ,
117
129
op : 'ui.long-task' ,
118
- startTime,
119
130
attributes : {
120
131
[ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.browser.metrics' ,
121
132
} ,
122
133
} ) ;
123
- if ( span ) {
124
- span . end ( startTime + duration ) ;
125
- }
126
134
}
127
135
} ) ;
128
136
}
You can’t perform that action at this time.
0 commit comments