@@ -134,6 +134,43 @@ export class MetricsInstrumentation {
134
134
135
135
// Measurements are only available for pageload transactions
136
136
if ( transaction . op === 'pageload' ) {
137
+ // normalize applicable web vital values to be relative to transaction.startTimestamp
138
+
139
+ const timeOrigin = msToSec ( performance . timeOrigin ) ;
140
+
141
+ [ 'fcp' , 'fp' , 'lcp' , 'ttfb' ] . forEach ( name => {
142
+ if ( ! this . _measurements [ name ] || timeOrigin >= transaction . startTimestamp ) {
143
+ return ;
144
+ }
145
+
146
+ // The web vitals, fcp, fp, lcp, and ttfb, all measure relative to timeOrigin.
147
+ // Unfortunately, timeOrigin is not captured within the transaction span data, so these web vitals will need
148
+ // to be adjusted to be relative to transaction.startTimestamp.
149
+
150
+ const oldValue = this . _measurements [ name ] . value ;
151
+ const measurementTimestamp = timeOrigin + msToSec ( oldValue ) ;
152
+ // normalizedValue should be in milliseconds
153
+ const normalizedValue = ( measurementTimestamp - transaction . startTimestamp ) * 1000 ;
154
+
155
+ const delta = normalizedValue - oldValue ;
156
+ logger . log (
157
+ `[Measurements] Normalized ${ name } from ${ this . _measurements [ name ] . value } to ${ normalizedValue } (${ delta } )` ,
158
+ ) ;
159
+
160
+ this . _measurements [ name ] . value = normalizedValue ;
161
+ } ) ;
162
+
163
+ if ( this . _measurements [ 'mark.fid' ] && this . _measurements [ 'fid' ] ) {
164
+ // create span for FID
165
+
166
+ _startChild ( transaction , {
167
+ description : 'first input delay' ,
168
+ endTimestamp : this . _measurements [ 'mark.fid' ] . value + msToSec ( this . _measurements [ 'fid' ] . value ) ,
169
+ op : 'web.vitals' ,
170
+ startTimestamp : this . _measurements [ 'mark.fid' ] . value ,
171
+ } ) ;
172
+ }
173
+
137
174
transaction . setMeasurements ( this . _measurements ) ;
138
175
}
139
176
}
@@ -253,6 +290,7 @@ function addNavigationSpans(transaction: Transaction, entry: Record<string, any>
253
290
addPerformanceNavigationTiming ( transaction , entry , 'loadEvent' , timeOrigin ) ;
254
291
addPerformanceNavigationTiming ( transaction , entry , 'connect' , timeOrigin ) ;
255
292
addPerformanceNavigationTiming ( transaction , entry , 'secureConnection' , timeOrigin , 'connectEnd' ) ;
293
+ addPerformanceNavigationTiming ( transaction , entry , 'fetch' , timeOrigin , 'domainLookupStart' ) ;
256
294
addPerformanceNavigationTiming ( transaction , entry , 'domainLookup' , timeOrigin ) ;
257
295
addRequest ( transaction , entry , timeOrigin ) ;
258
296
}
0 commit comments