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-6801] Collect resource worker processing time #3118

Merged
merged 7 commits into from
Nov 18, 2024
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 @@ -46,6 +46,7 @@ export interface RumPerformanceResourceTiming {
startTime: RelativeTime
duration: Duration
fetchStart: RelativeTime
workerStart: RelativeTime
domainLookupStart: RelativeTime
domainLookupEnd: RelativeTime
connectStart: RelativeTime
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/browser/performanceUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('getNavigationEntry', () => {
duration: jasmine.any(Number),

fetchStart: jasmine.any(Number),
workerStart: jasmine.any(Number),
domainLookupStart: jasmine.any(Number),
domainLookupEnd: jasmine.any(Number),
connectStart: jasmine.any(Number),
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/browser/performanceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function getNavigationEntry(): RumPerformanceNavigationTiming {
decodedBodySize: 0,
encodedBodySize: 0,
transferSize: 0,
workerStart: 0 as RelativeTime,
toJSON: () => assign({}, entry, { toJSON: undefined }),
},
timings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ describe('matchRequestResourceEntry', () => {
name: FAKE_URL,
// fetchStart < startTime is invalid
fetchStart: 0 as RelativeTime,
workerStart: 0 as RelativeTime,
startTime: 200 as RelativeTime,
})
globalPerformanceObjectMock.addPerformanceEntry(entry)
Expand Down
17 changes: 17 additions & 0 deletions packages/rum-core/src/domain/resource/resourceUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ describe('computeResourceEntryDetails', () => {
})
})

it('should compute worker timing when workerStart < fetchStart', () => {
const resourceTiming = generateResourceWith({
workerStart: 11 as RelativeTime,
fetchStart: 12 as RelativeTime,
})
const details = computeResourceEntryDetails(resourceTiming)
expect(details).toEqual({
worker: { start: 1e6 as ServerDuration, duration: 1e6 as ServerDuration },
connect: { start: 5e6 as ServerDuration, duration: 2e6 as ServerDuration },
dns: { start: 3e6 as ServerDuration, duration: 1e6 as ServerDuration },
download: { start: 40e6 as ServerDuration, duration: 10e6 as ServerDuration },
first_byte: { start: 10e6 as ServerDuration, duration: 30e6 as ServerDuration },
redirect: { start: 0 as ServerDuration, duration: 1e6 as ServerDuration },
ssl: { start: 6e6 as ServerDuration, duration: 1e6 as ServerDuration },
})
})

it('should not compute redirect timing when no redirect', () => {
expect(
computeResourceEntryDetails(
Expand Down
7 changes: 7 additions & 0 deletions packages/rum-core/src/domain/resource/resourceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { RumPerformanceResourceTiming } from '../../browser/performanceObse
import type { ResourceEntryDetailsElement } from '../../rawRumEvent.types'

export interface ResourceEntryDetails {
worker?: ResourceEntryDetailsElement
redirect?: ResourceEntryDetailsElement
dns?: ResourceEntryDetailsElement
connect?: ResourceEntryDetailsElement
Expand Down Expand Up @@ -91,6 +92,7 @@ export function computeResourceEntryDetails(entry: RumPerformanceResourceTiming)
const {
startTime,
fetchStart,
workerStart,
redirectStart,
redirectEnd,
domainLookupStart,
Expand All @@ -108,6 +110,11 @@ export function computeResourceEntryDetails(entry: RumPerformanceResourceTiming)
first_byte: formatTiming(startTime, requestStart, responseStart),
}

// Make sure a worker processing time is recorded
if (workerStart < fetchStart) {
details.worker = formatTiming(startTime, workerStart, fetchStart)
RomanGaignault marked this conversation as resolved.
Show resolved Hide resolved
}

// Make sure a connection occurred
if (fetchStart < connectEnd) {
details.connect = formatTiming(startTime, connectStart, connectEnd)
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 @@ -46,6 +46,7 @@ export interface RawRumResourceEvent {
dns?: ResourceEntryDetailsElement
connect?: ResourceEntryDetailsElement
ssl?: ResourceEntryDetailsElement
worker?: ResourceEntryDetailsElement
first_byte?: ResourceEntryDetailsElement
download?: ResourceEntryDetailsElement
protocol?: string
Expand Down
22 changes: 22 additions & 0 deletions packages/rum-core/src/rumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,20 @@ export type RumResourceEvent = CommonProperties &
* Render blocking status of the resource
*/
readonly render_blocking_status?: 'blocking' | 'non-blocking'
/**
* Worker phase properties
*/
readonly worker?: {
/**
* Duration in nanoseconds of the resource worker phase
*/
readonly duration: number
/**
* Duration in nanoseconds between start of the request and start of the worker phase
*/
readonly start: number
[k: string]: unknown
}
/**
* Redirect phase properties
*/
Expand Down Expand Up @@ -803,6 +817,14 @@ export type RumViewEvent = CommonProperties &
* Duration in ns to the view is considered loaded
*/
readonly loading_time?: number
/**
* Duration in ns from the moment the view was started until all the initial network requests settled
*/
readonly network_settled_time?: number
/**
* Duration in ns to from the last interaction on previous view to the moment the current view was displayed
*/
readonly interaction_to_next_view_time?: number
/**
* Type of the loading of the view
*/
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export function createPerformanceEntry<T extends RumPerformanceEntryType>(
domainLookupStart: 200 as RelativeTime,
duration: 100 as Duration,
entryType: RumPerformanceEntryType.RESOURCE,
workerStart: 200 as RelativeTime,
fetchStart: 200 as RelativeTime,
name: 'https://resource.com/valid',
redirectEnd: 200 as RelativeTime,
Expand Down