-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(web-vitals): Adjust some web vitals to be relative to fetchStart and some other improvements #3019
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
fix(web-vitals): Adjust some web vitals to be relative to fetchStart and some other improvements #3019
Changes from 4 commits
726b175
886628a
63095df
8ba3e0a
8d7ae28
f086c8e
c7ea73f
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 |
---|---|---|
|
@@ -134,6 +134,43 @@ export class MetricsInstrumentation { | |
|
||
// Measurements are only available for pageload transactions | ||
if (transaction.op === 'pageload') { | ||
// normalize applicable web vital values to be relative to transaction.startTimestamp | ||
|
||
const timeOrigin = msToSec(performance.timeOrigin); | ||
|
||
['fcp', 'fp', 'lcp', 'ttfb'].forEach(name => { | ||
if (!this._measurements[name] || timeOrigin >= transaction.startTimestamp) { | ||
return; | ||
} | ||
|
||
// The web vitals, fcp, fp, lcp, and ttfb, all measure relative to timeOrigin. | ||
// Unfortunately, timeOrigin is not captured within the transaction span data, so these web vitals will need | ||
// to be adjusted to be relative to transaction.startTimestamp. | ||
|
||
const oldValue = this._measurements[name].value; | ||
const measurementTimestamp = timeOrigin + msToSec(oldValue); | ||
// normalizedValue should be in milliseconds | ||
const normalizedValue = (measurementTimestamp - transaction.startTimestamp) * 1000; | ||
|
||
const delta = normalizedValue - oldValue; | ||
logger.log( | ||
`[Measurements] Normalized ${name} from ${this._measurements[name].value} to ${normalizedValue} (${delta})`, | ||
); | ||
|
||
this._measurements[name] = { value: normalizedValue }; | ||
}); | ||
|
||
if (this._measurements['mark.fid'] && this._measurements['fid']) { | ||
// create span for FID | ||
|
||
_startChild(transaction, { | ||
description: 'first input delay', | ||
endTimestamp: this._measurements['mark.fid'].value + msToSec(this._measurements['fid'].value), | ||
op: 'web vitals', | ||
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. Should this be 'vitals' to match the more generic name we'll likely use in the future? 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. Right now we've not committed to using that term as a generic umbrella. We've only used "web vitals" thus far. 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. Is the fact that the op is currently two words going to mean that when searching for it, you have to put it in quotes? (I would guess that the answer is yes.) If so, can we make this one word (even if it's 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.
|
||
startTimestamp: this._measurements['mark.fid'].value, | ||
}); | ||
} | ||
|
||
transaction.setMeasurements(this._measurements); | ||
} | ||
} | ||
|
@@ -253,6 +290,7 @@ function addNavigationSpans(transaction: Transaction, entry: Record<string, any> | |
addPerformanceNavigationTiming(transaction, entry, 'loadEvent', timeOrigin); | ||
addPerformanceNavigationTiming(transaction, entry, 'connect', timeOrigin); | ||
addPerformanceNavigationTiming(transaction, entry, 'secureConnection', timeOrigin, 'connectEnd'); | ||
addPerformanceNavigationTiming(transaction, entry, 'fetch', timeOrigin, 'domainLookupStart'); | ||
addPerformanceNavigationTiming(transaction, entry, 'domainLookup', timeOrigin); | ||
addRequest(transaction, entry, timeOrigin); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.