@@ -79,14 +79,14 @@ export class MetricsInstrumentation {
79
79
80
80
if ( entry . name === 'first-paint' && shouldRecord ) {
81
81
IS_DEBUG_BUILD && logger . log ( '[Measurements] Adding FP' ) ;
82
- this . _measurements [ 'fp' ] = { value : entry . startTime } ;
83
- this . _measurements [ 'mark.fp' ] = { value : startTimestamp } ;
82
+ this . _measurements [ 'fp' ] = { value : entry . startTime , unit : 'millisecond' } ;
83
+ this . _measurements [ 'mark.fp' ] = { value : startTimestamp , unit : 'second' } ;
84
84
}
85
85
86
86
if ( entry . name === 'first-contentful-paint' && shouldRecord ) {
87
87
IS_DEBUG_BUILD && logger . log ( '[Measurements] Adding FCP' ) ;
88
- this . _measurements [ 'fcp' ] = { value : entry . startTime } ;
89
- this . _measurements [ 'mark.fcp' ] = { value : startTimestamp } ;
88
+ this . _measurements [ 'fcp' ] = { value : entry . startTime , unit : 'millisecond' } ;
89
+ this . _measurements [ 'mark.fcp' ] = { value : startTimestamp , unit : 'second' } ;
90
90
}
91
91
92
92
break ;
@@ -115,12 +115,18 @@ export class MetricsInstrumentation {
115
115
// start of the response in milliseconds
116
116
if ( typeof responseStartTimestamp === 'number' ) {
117
117
IS_DEBUG_BUILD && logger . log ( '[Measurements] Adding TTFB' ) ;
118
- this . _measurements [ 'ttfb' ] = { value : ( responseStartTimestamp - transaction . startTimestamp ) * 1000 } ;
118
+ this . _measurements [ 'ttfb' ] = {
119
+ value : ( responseStartTimestamp - transaction . startTimestamp ) * 1000 ,
120
+ unit : 'millisecond' ,
121
+ } ;
119
122
120
123
if ( typeof requestStartTimestamp === 'number' && requestStartTimestamp <= responseStartTimestamp ) {
121
124
// Capture the time spent making the request and receiving the first byte of the response.
122
125
// This is the time between the start of the request and the start of the response in milliseconds.
123
- this . _measurements [ 'ttfb.requestTime' ] = { value : ( responseStartTimestamp - requestStartTimestamp ) * 1000 } ;
126
+ this . _measurements [ 'ttfb.requestTime' ] = {
127
+ value : ( responseStartTimestamp - requestStartTimestamp ) * 1000 ,
128
+ unit : 'second' ,
129
+ } ;
124
130
}
125
131
}
126
132
@@ -162,7 +168,14 @@ export class MetricsInstrumentation {
162
168
delete this . _measurements . cls ;
163
169
}
164
170
165
- transaction . setMeasurements ( this . _measurements ) ;
171
+ Object . keys ( this . _measurements ) . forEach ( measurementName => {
172
+ transaction . setMeasurement (
173
+ measurementName ,
174
+ this . _measurements [ measurementName ] . value ,
175
+ this . _measurements [ measurementName ] . unit ,
176
+ ) ;
177
+ } ) ;
178
+
166
179
tagMetricInfo ( transaction , this . _lcpEntry , this . _clsEntry ) ;
167
180
transaction . setTag ( 'sentry_reportAllChanges' , this . _reportAllChanges ) ;
168
181
}
@@ -189,11 +202,11 @@ export class MetricsInstrumentation {
189
202
}
190
203
191
204
if ( isMeasurementValue ( connection . rtt ) ) {
192
- this . _measurements [ 'connection.rtt' ] = { value : connection . rtt as number } ;
205
+ this . _measurements [ 'connection.rtt' ] = { value : connection . rtt , unit : 'millisecond' } ;
193
206
}
194
207
195
208
if ( isMeasurementValue ( connection . downlink ) ) {
196
- this . _measurements [ 'connection.downlink' ] = { value : connection . downlink as number } ;
209
+ this . _measurements [ 'connection.downlink' ] = { value : connection . downlink , unit : '' } ; // unit is empty string for now, while relay doesn't support download speed units
197
210
}
198
211
}
199
212
@@ -218,7 +231,7 @@ export class MetricsInstrumentation {
218
231
}
219
232
220
233
IS_DEBUG_BUILD && logger . log ( '[Measurements] Adding CLS' ) ;
221
- this . _measurements [ 'cls' ] = { value : metric . value } ;
234
+ this . _measurements [ 'cls' ] = { value : metric . value , unit : 'millisecond' } ;
222
235
this . _clsEntry = entry as LayoutShift ;
223
236
} ) ;
224
237
}
@@ -234,8 +247,8 @@ export class MetricsInstrumentation {
234
247
const timeOrigin = msToSec ( browserPerformanceTimeOrigin as number ) ;
235
248
const startTime = msToSec ( entry . startTime ) ;
236
249
IS_DEBUG_BUILD && logger . log ( '[Measurements] Adding LCP' ) ;
237
- this . _measurements [ 'lcp' ] = { value : metric . value } ;
238
- this . _measurements [ 'mark.lcp' ] = { value : timeOrigin + startTime } ;
250
+ this . _measurements [ 'lcp' ] = { value : metric . value , unit : 'millisecond' } ;
251
+ this . _measurements [ 'mark.lcp' ] = { value : timeOrigin + startTime , unit : 'second' } ;
239
252
this . _lcpEntry = entry as LargestContentfulPaint ;
240
253
} , this . _reportAllChanges ) ;
241
254
}
@@ -251,8 +264,8 @@ export class MetricsInstrumentation {
251
264
const timeOrigin = msToSec ( browserPerformanceTimeOrigin as number ) ;
252
265
const startTime = msToSec ( entry . startTime ) ;
253
266
IS_DEBUG_BUILD && logger . log ( '[Measurements] Adding FID' ) ;
254
- this . _measurements [ 'fid' ] = { value : metric . value } ;
255
- this . _measurements [ 'mark.fid' ] = { value : timeOrigin + startTime } ;
267
+ this . _measurements [ 'fid' ] = { value : metric . value , unit : 'millisecond' } ;
268
+ this . _measurements [ 'mark.fid' ] = { value : timeOrigin + startTime , unit : 'second' } ;
256
269
} ) ;
257
270
}
258
271
}
@@ -392,7 +405,7 @@ export function _startChild(transaction: Transaction, { startTimestamp, ...ctx }
392
405
/**
393
406
* Checks if a given value is a valid measurement value.
394
407
*/
395
- function isMeasurementValue ( value : any ) : boolean {
408
+ function isMeasurementValue ( value : unknown ) : value is number {
396
409
return typeof value === 'number' && isFinite ( value ) ;
397
410
}
398
411
0 commit comments