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-5090] Collect resource protocol #3087

Merged
merged 5 commits into from
Oct 25, 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 @@ -59,6 +59,7 @@ export interface RumPerformanceResourceTiming {
decodedBodySize: number
encodedBodySize: number
transferSize: number
nextHopProtocol?: string
renderBlockingStatus?: string
traceId?: string
toJSON(): Omit<PerformanceEntry, 'toJSON'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('resourceCollection', () => {
download: jasmine.any(Object),
first_byte: jasmine.any(Object),
status_code: 200,
protocol: 'HTTP/1.0',
render_blocking_status: 'blocking',
},
type: RumEventType.RESOURCE,
Expand Down Expand Up @@ -116,6 +117,7 @@ describe('resourceCollection', () => {
duration: (100 * 1e6) as ServerDuration,
method: 'GET',
status_code: 200,
protocol: undefined,
type: ResourceType.XHR,
url: 'https://resource.com/valid',
},
Expand Down Expand Up @@ -229,6 +231,7 @@ describe('resourceCollection', () => {
duration: (100 * 1e6) as ServerDuration,
method: 'GET',
status_code: 200,
protocol: undefined,
type: ResourceType.FETCH,
url: 'https://resource.com/valid',
},
Expand Down
3 changes: 3 additions & 0 deletions packages/rum-core/src/domain/resource/resourceCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
computeResourceEntryDuration,
computeResourceEntryType,
computeResourceEntrySize,
computeResourceEntryProtocol,
isResourceEntryRequestType,
isLongDataUrl,
sanitizeDataUrl,
Expand Down Expand Up @@ -104,6 +105,7 @@ function processRequest(
duration,
method: request.method,
status_code: request.status,
protocol: matchingTiming && computeResourceEntryProtocol(matchingTiming),
url: isLongDataUrl(request.url) ? sanitizeDataUrl(request.url) : request.url,
},
type: RumEventType.RESOURCE as const,
Expand Down Expand Up @@ -152,6 +154,7 @@ function processResourceEntry(
type,
url: entry.name,
status_code: discardZeroStatus(entry.responseStatus),
protocol: computeResourceEntryProtocol(entry),
},
type: RumEventType.RESOURCE as const,
_dd: {
Expand Down
9 changes: 9 additions & 0 deletions packages/rum-core/src/domain/resource/resourceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ function formatTiming(origin: RelativeTime, start: RelativeTime, end: RelativeTi
}
}

/**
* The 'nextHopProtocol' is an empty string for cross-origin resources without CORS headers,
* meaning the protocol is unknown, and we shouldn't report it.
* https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/nextHopProtocol#cross-origin_resources
*/
export function computeResourceEntryProtocol(entry: RumPerformanceResourceTiming) {
return entry.nextHopProtocol === '' ? undefined : entry.nextHopProtocol
}

export function computeResourceEntrySize(entry: RumPerformanceResourceTiming) {
// Make sure a request actually occurred
if (entry.startTime < entry.responseStart) {
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 @@ -48,6 +48,7 @@ export interface RawRumResourceEvent {
ssl?: ResourceEntryDetailsElement
first_byte?: ResourceEntryDetailsElement
download?: ResourceEntryDetailsElement
protocol?: string
}
_dd: {
trace_id?: 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 @@ -702,6 +702,10 @@ export type RumResourceEvent = CommonProperties &
readonly start: number
[k: string]: unknown
}
/**
* Network protocol used to fetch the resource (e.g., 'http/1.1', 'h2')
*/
readonly protocol?: string
/**
* The provider for this resource
*/
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 @@ -259,6 +259,7 @@ export function createPerformanceEntry<T extends RumPerformanceEntryType>(
secureConnectionStart: 200 as RelativeTime,
startTime: 200 as RelativeTime,
responseStatus: 200,
nextHopProtocol: 'HTTP/1.0',
},
overrides
) as EntryTypeToReturnType[T]
Expand Down