Skip to content
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

🔊[RUM-2324] Telemetry on other wrong LCP cases #2531

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core/src/tools/experimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export enum ExperimentalFeature {
RESOURCE_PAGE_STATES = 'resource_page_states',
COLLECT_FLUSH_REASON = 'collect_flush_reason',
ZERO_LCP_TELEMETRY = 'zero_lcp_telemetry',
SCROLLMAP = 'scrollmap',
DISABLE_REPLAY_INLINE_CSS = 'disable_replay_inline_css',
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/browser/performanceCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface RumLargestContentfulPaintTiming {
startTime: RelativeTime
size: number
element?: Element
toJSON(): Omit<PerformanceEntry, 'toJSON'>
toJSON(): Omit<RumLargestContentfulPaintTiming, 'toJSON'>
}

export interface RumFirstInputTiming {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export interface LargestContentfulPaint {
targetSelector?: string
}

let zeroLcpReported = false
let previousNonZeroLcp: Omit<PerformanceEntry, 'toJSON'> | undefined
type SerializableLCP = Omit<RumLargestContentfulPaintTiming, 'toJSON' | 'element'>

let wrongLcpReported = false
let previousLcp: SerializableLCP

/**
* Track the largest contentful paint (LCP) occurring during the initial View. This can yield
Expand Down Expand Up @@ -75,7 +77,13 @@ export function trackLargestContentfulPaint(
}

if (isExperimentalFeatureEnabled(ExperimentalFeature.ZERO_LCP_TELEMETRY)) {
monitorZeroLcpEntry(lcpEntry)
monitorLcpEntries(
lcpEntry,
entries.filter(
(entry): entry is RumLargestContentfulPaintTiming =>
entry.entryType === RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT
)
)
}

callback({
Expand All @@ -94,24 +102,39 @@ export function trackLargestContentfulPaint(
}
}

function monitorZeroLcpEntry(lcpEntry: RumLargestContentfulPaintTiming) {
if (!zeroLcpReported && lcpEntry.startTime !== 0) {
previousNonZeroLcp = lcpEntry.toJSON()
function monitorLcpEntries(lcpEntry: RumLargestContentfulPaintTiming, lcpEntries: RumLargestContentfulPaintTiming[]) {
if (wrongLcpReported) {
return
}

if (!zeroLcpReported && lcpEntry.startTime === 0) {
zeroLcpReported = true
const wrongLcpDetected =
lcpEntry.startTime === 0
? 'LCP with startTime = 0'
: previousLcp !== undefined && lcpEntry.startTime < previousLcp.startTime
? 'LCP with startTime < previous LCP'
: previousLcp !== undefined && lcpEntry.size < previousLcp.size
? 'LCP with size < previous LCP'
: undefined

if (wrongLcpDetected) {
wrongLcpReported = true

addTelemetryDebug('LCP with startTime = 0', {
addTelemetryDebug(wrongLcpDetected, {
debug: {
entry: lcpEntry.toJSON(),
previousNonZeroLcp,
navigationStart: performance.timing.navigationStart,
entry: toSerializableLCP(lcpEntry),
previousLcp,
timeOrigin: performance.timeOrigin,
now: relativeNow(),
visibilityState: document.visibilityState,
prerendering: (document as any).prerendering,
lcpEntries: lcpEntries.map(toSerializableLCP),
},
})
}

previousLcp = toSerializableLCP(lcpEntry)
}

function toSerializableLCP(entry: RumLargestContentfulPaintTiming): SerializableLCP {
const jsonEntry = entry.toJSON()
delete jsonEntry.element
return jsonEntry
}