-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(web-vitals): Capture information about the LCP element culprit #3427
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 all commits
ea1c3bb
5f42677
fb850b3
c513a29
875264e
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,14 +1,14 @@ | ||
/* eslint-disable max-lines */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Measurements, SpanContext } from '@sentry/types'; | ||
import { browserPerformanceTimeOrigin, getGlobalObject, logger } from '@sentry/utils'; | ||
import { browserPerformanceTimeOrigin, getGlobalObject, htmlTreeAsString, logger } from '@sentry/utils'; | ||
|
||
import { Span } from '../span'; | ||
import { Transaction } from '../transaction'; | ||
import { msToSec } from '../utils'; | ||
import { getCLS } from './web-vitals/getCLS'; | ||
import { getFID } from './web-vitals/getFID'; | ||
import { getLCP } from './web-vitals/getLCP'; | ||
import { getLCP, LargestContentfulPaint } from './web-vitals/getLCP'; | ||
import { getTTFB } from './web-vitals/getTTFB'; | ||
import { getFirstHidden } from './web-vitals/lib/getFirstHidden'; | ||
import { NavigatorDeviceMemory, NavigatorNetworkInformation } from './web-vitals/types'; | ||
|
@@ -20,6 +20,7 @@ export class MetricsInstrumentation { | |
private _measurements: Measurements = {}; | ||
|
||
private _performanceCursor: number = 0; | ||
private _lcpEntry: LargestContentfulPaint | undefined; | ||
|
||
public constructor() { | ||
if (global && global.performance) { | ||
|
@@ -170,6 +171,26 @@ export class MetricsInstrumentation { | |
} | ||
|
||
transaction.setMeasurements(this._measurements); | ||
|
||
if (this._lcpEntry) { | ||
logger.log('[Measurements] Adding LCP Data'); | ||
// Capture Properties of the LCP element that contributes to the LCP. | ||
|
||
if (this._lcpEntry.element) { | ||
transaction.setTag('lcp.element', htmlTreeAsString(this._lcpEntry.element)); | ||
} | ||
|
||
if (this._lcpEntry.id) { | ||
transaction.setTag('lcp.id', this._lcpEntry.id); | ||
} | ||
|
||
if (this._lcpEntry.url) { | ||
// Trim URL to the first 200 characters. | ||
transaction.setTag('lcp.url', this._lcpEntry.url.trim().slice(0, 200)); | ||
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. @dashed do you think it will be important to disambiguate in Sentry when the attribute was truncated or not? 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. @k-fish any thoughts on this? 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 only way to clearly disambiguate it would be to set another tag when it was truncated, I feel like this is overkill considering we're not sure this is even necessary. I'd wait on adding any additional data until we see a clear case for it in the product. 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. @rhcarvalho @k-fish I'll merge this in as is. Once we surface this on the product on the segment explorer, it'll be obvious if there's a need to disambiguate it. And if there is, we can follow up with another PR. |
||
} | ||
|
||
transaction.setTag('lcp.size', this._lcpEntry.size); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -241,6 +262,7 @@ export class MetricsInstrumentation { | |
logger.log('[Measurements] Adding LCP'); | ||
this._measurements['lcp'] = { value: metric.value }; | ||
this._measurements['mark.lcp'] = { value: timeOrigin + startTime }; | ||
this._lcpEntry = entry as LargestContentfulPaint; | ||
}); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.