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-6563] Attribute ressource URL to LCP #3154

Merged
merged 5 commits into from
Jan 29, 2025
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: 1 addition & 0 deletions packages/rum-core/src/browser/performanceObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface RumLargestContentfulPaintTiming {
startTime: RelativeTime
size: number
element?: Element
url?: string
toJSON(): Omit<RumLargestContentfulPaintTiming, 'toJSON'>
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/domain/view/trackViews.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ describe('view metrics', () => {
jasmine.objectContaining({
firstContentfulPaint: 123 as Duration,
navigationTimings: jasmine.any(Object),
largestContentfulPaint: { value: 789 as Duration, targetSelector: undefined },
largestContentfulPaint: { value: 789 as Duration, targetSelector: undefined, resourceUrl: undefined },
})
)
})
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/domain/view/viewCollection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe('viewCollection', () => {
lcp: {
timestamp: (10 * 1e6) as ServerDuration,
target_selector: undefined,
resource_url: undefined,
},
},
resource: {
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/domain/view/viewCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function computeViewPerformanceData(
lcp: largestContentfulPaint && {
timestamp: toServerDuration(largestContentfulPaint.value),
target_selector: largestContentfulPaint.targetSelector,
resource_url: largestContentfulPaint.resourceUrl,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ describe('trackLargestContentfulPaint', () => {
startLCPTracking()
notifyPerformanceEntries([createPerformanceEntry(RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT)])

expect(lcpCallback).toHaveBeenCalledOnceWith({ value: 789 as RelativeTime, targetSelector: undefined })
expect(lcpCallback).toHaveBeenCalledOnceWith({
value: 789 as RelativeTime,
targetSelector: undefined,
resourceUrl: undefined,
})
})

it('should provide the largest contentful paint target selector', () => {
Expand All @@ -56,7 +60,26 @@ describe('trackLargestContentfulPaint', () => {
}),
])

expect(lcpCallback).toHaveBeenCalledOnceWith({ value: 789 as RelativeTime, targetSelector: '#lcp-target-element' })
expect(lcpCallback).toHaveBeenCalledOnceWith({
value: 789 as RelativeTime,
targetSelector: '#lcp-target-element',
resourceUrl: undefined,
})
})

it('should provide the largest contentful paint target url', () => {
startLCPTracking()
notifyPerformanceEntries([
createPerformanceEntry(RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT, {
url: 'https://example.com/lcp-resource',
}),
])

expect(lcpCallback).toHaveBeenCalledOnceWith({
value: 789 as RelativeTime,
targetSelector: undefined,
resourceUrl: 'https://example.com/lcp-resource',
})
})

it('should be discarded if it is reported after a user interaction', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const LCP_MAXIMUM_DELAY = 10 * ONE_MINUTE
export interface LargestContentfulPaint {
value: RelativeTime
targetSelector?: string
resourceUrl?: string
}

/**
Expand Down Expand Up @@ -57,7 +58,6 @@ export function trackLargestContentfulPaint(
// https://bugs.chromium.org/p/chromium/issues/detail?id=1516655
entry.size > biggestLcpSize
)

if (lcpEntry) {
let lcpTargetSelector
if (lcpEntry.element) {
Expand All @@ -67,6 +67,7 @@ export function trackLargestContentfulPaint(
callback({
value: lcpEntry.startTime,
targetSelector: lcpTargetSelector,
resourceUrl: lcpEntry.url,
})
biggestLcpSize = lcpEntry.size
}
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/rawRumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export interface ViewPerformanceData {
lcp?: {
timestamp: ServerDuration
target_selector?: string
resource_url?: string
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/rum-core/src/rumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,10 @@ export interface ViewPerformanceData {
* CSS selector path of the largest contentful paint element
*/
readonly target_selector?: string
/**
* URL of the largest contentful paint element
*/
readonly resource_url?: string
[k: string]: unknown
}
[k: string]: unknown
Expand Down
Loading