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 LCP with startTime to 0 #2515

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 0 deletions packages/core/src/tools/experimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum ExperimentalFeature {
FEATURE_FLAGS = 'feature_flags',
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
1 change: 1 addition & 0 deletions packages/rum-core/src/browser/performanceCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface RumLargestContentfulPaintTiming {
startTime: RelativeTime
size: number
element?: Element
toJSON(): Omit<PerformanceEntry, 'toJSON'>
}

export interface RumFirstInputTiming {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import type { RelativeTime } from '@datadog/browser-core'
import { DOM_EVENT, ONE_MINUTE, addEventListeners, findLast } from '@datadog/browser-core'
import {
DOM_EVENT,
ExperimentalFeature,
ONE_MINUTE,
addEventListeners,
addTelemetryDebug,
findLast,
isExperimentalFeatureEnabled,
relativeNow,
} from '@datadog/browser-core'
import { LifeCycleEventType } from '../../lifeCycle'
import type { LifeCycle } from '../../lifeCycle'
import type { RumConfiguration } from '../../configuration'
Expand All @@ -16,6 +25,8 @@ export interface LargestContentfulPaint {
value: RelativeTime
targetSelector?: string
}

let zeroLcpReported = false
/**
* Track the largest contentful paint (LCP) occurring during the initial View. This can yield
* multiple values, only the most recent one should be used.
Expand Down Expand Up @@ -61,6 +72,22 @@ export function trackLargestContentfulPaint(
lcpTargetSelector = getSelectorFromElement(lcpEntry.element, configuration.actionNameAttribute)
}

if (
!zeroLcpReported &&
lcpEntry.startTime === 0 &&
isExperimentalFeatureEnabled(ExperimentalFeature.ZERO_LCP_TELEMETRY)
) {
zeroLcpReported = true
addTelemetryDebug('LCP with startTime = 0', {
bcaudan marked this conversation as resolved.
Show resolved Hide resolved
debug: {
entry: lcpEntry.toJSON(),
navigationStart: performance.timing.navigationStart,
timeOrigin: performance.timeOrigin,
now: relativeNow(),
visibilityState: document.visibilityState,
},
})
}
callback({
value: lcpEntry.startTime,
targetSelector: lcpTargetSelector,
Expand Down