-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(measurements): Update setMeasurements
to only set a single measurement
#4920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
605fe42
dd9f8c8
e617f7f
fad13a1
14c62ff
afcdaee
3a95f2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* eslint-disable max-lines */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Measurements, SpanContext } from '@sentry/types'; | ||
import { SpanContext } from '@sentry/types'; | ||
import { browserPerformanceTimeOrigin, getGlobalObject, htmlTreeAsString, isNodeEnv, logger } from '@sentry/utils'; | ||
|
||
import { IS_DEBUG_BUILD } from '../flags'; | ||
|
@@ -17,7 +17,7 @@ const global = getGlobalObject<Window>(); | |
|
||
/** Class tracking metrics */ | ||
export class MetricsInstrumentation { | ||
private _measurements: Measurements = {}; | ||
private _measurements: Record<string, { value: number }> = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to add units to any of these? Most vitals like LCP are in seconds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added units here: afcdaee |
||
|
||
private _performanceCursor: number = 0; | ||
private _lcpEntry: LargestContentfulPaint | undefined; | ||
|
@@ -162,7 +162,10 @@ export class MetricsInstrumentation { | |
delete this._measurements.cls; | ||
} | ||
|
||
transaction.setMeasurements(this._measurements); | ||
Object.keys(this._measurements).forEach(measurementName => { | ||
transaction.setMeasurement(measurementName, this._measurements[measurementName].value); | ||
}); | ||
|
||
tagMetricInfo(transaction, this._lcpEntry, this._clsEntry); | ||
transaction.setTag('sentry_reportAllChanges', this._reportAllChanges); | ||
} | ||
|
@@ -189,11 +192,11 @@ export class MetricsInstrumentation { | |
} | ||
|
||
if (isMeasurementValue(connection.rtt)) { | ||
this._measurements['connection.rtt'] = { value: connection.rtt as number }; | ||
this._measurements['connection.rtt'] = { value: connection.rtt }; | ||
} | ||
|
||
if (isMeasurementValue(connection.downlink)) { | ||
this._measurements['connection.downlink'] = { value: connection.downlink as number }; | ||
this._measurements['connection.downlink'] = { value: connection.downlink }; | ||
} | ||
} | ||
|
||
|
@@ -392,7 +395,7 @@ export function _startChild(transaction: Transaction, { startTimestamp, ...ctx } | |
/** | ||
* Checks if a given value is a valid measurement value. | ||
*/ | ||
function isMeasurementValue(value: any): boolean { | ||
function isMeasurementValue(value: unknown): value is number { | ||
return typeof value === 'number' && isFinite(value); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { getCurrentHub, Hub } from '@sentry/hub'; | |
import { | ||
Event, | ||
Measurements, | ||
MeasurementUnit, | ||
Transaction as TransactionInterface, | ||
TransactionContext, | ||
TransactionMetadata, | ||
|
@@ -68,11 +69,14 @@ export class Transaction extends SpanClass implements TransactionInterface { | |
} | ||
|
||
/** | ||
* Set observed measurements for this transaction. | ||
* Set observed measurement for this transaction. | ||
* @param name Name of the measurement | ||
* @param value Value of the measurement | ||
* @param unit Unit of the measurement. (Defaults to 'ms' - milliseconds) | ||
* @hidden | ||
*/ | ||
public setMeasurements(measurements: Measurements): void { | ||
this._measurements = { ...measurements }; | ||
public setMeasurement(name: string, value: number, unit: MeasurementUnit = 'ms'): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default should be an empty string, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I know units are basically free form text, I agree. Changed in dd9f8c8. |
||
this._measurements[name] = { value, unit }; | ||
} | ||
|
||
/** | ||
|
Uh oh!
There was an error while loading. Please reload this page.