11/* eslint-disable max-lines */
22/* eslint-disable @typescript-eslint/no-explicit-any */
3- import { Measurements , SpanContext } from '@sentry/types' ;
3+ import { SpanContext } from '@sentry/types' ;
44import { browserPerformanceTimeOrigin , getGlobalObject , htmlTreeAsString , isNodeEnv , logger } from '@sentry/utils' ;
55
66import { IS_DEBUG_BUILD } from '../flags' ;
@@ -17,7 +17,7 @@ const global = getGlobalObject<Window>();
1717
1818/** Class tracking metrics */
1919export class MetricsInstrumentation {
20- private _measurements : Measurements = { } ;
20+ private _measurements : Record < string , { value : number } > = { } ;
2121
2222 private _performanceCursor : number = 0 ;
2323 private _lcpEntry : LargestContentfulPaint | undefined ;
@@ -162,7 +162,10 @@ export class MetricsInstrumentation {
162162 delete this . _measurements . cls ;
163163 }
164164
165- transaction . setMeasurements ( this . _measurements ) ;
165+ Object . keys ( this . _measurements ) . forEach ( measurementName => {
166+ transaction . setMeasurement ( measurementName , this . _measurements [ measurementName ] . value ) ;
167+ } ) ;
168+
166169 tagMetricInfo ( transaction , this . _lcpEntry , this . _clsEntry ) ;
167170 transaction . setTag ( 'sentry_reportAllChanges' , this . _reportAllChanges ) ;
168171 }
@@ -189,11 +192,11 @@ export class MetricsInstrumentation {
189192 }
190193
191194 if ( isMeasurementValue ( connection . rtt ) ) {
192- this . _measurements [ 'connection.rtt' ] = { value : connection . rtt as number } ;
195+ this . _measurements [ 'connection.rtt' ] = { value : connection . rtt } ;
193196 }
194197
195198 if ( isMeasurementValue ( connection . downlink ) ) {
196- this . _measurements [ 'connection.downlink' ] = { value : connection . downlink as number } ;
199+ this . _measurements [ 'connection.downlink' ] = { value : connection . downlink } ;
197200 }
198201 }
199202
@@ -392,7 +395,7 @@ export function _startChild(transaction: Transaction, { startTimestamp, ...ctx }
392395/**
393396 * Checks if a given value is a valid measurement value.
394397 */
395- function isMeasurementValue ( value : any ) : boolean {
398+ function isMeasurementValue ( value : unknown ) : value is number {
396399 return typeof value === 'number' && isFinite ( value ) ;
397400}
398401
0 commit comments