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 4 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
1 change: 1 addition & 0 deletions packages/rum-core/src/domain/requestCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface RequestCompleteEvent {
method: string
url: string
status: number
protocol?: string
responseType?: string
startClocks: ClocksState
duration: Duration
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 All @@ -101,6 +102,7 @@ describe('resourceCollection', () => {
method: 'GET',
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
status: 200,
protocol: 'HTTP/1.0',
type: RequestType.XHR,
url: 'https://resource.com/valid',
xhr,
Expand All @@ -116,6 +118,7 @@ describe('resourceCollection', () => {
duration: (100 * 1e6) as ServerDuration,
method: 'GET',
status_code: 200,
protocol: 'HTTP/1.0',
type: ResourceType.XHR,
url: 'https://resource.com/valid',
},
Expand Down Expand Up @@ -212,6 +215,7 @@ describe('resourceCollection', () => {
method: 'GET',
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
status: 200,
protocol: 'HTTP/1.0',
type: RequestType.FETCH,
url: 'https://resource.com/valid',
response,
Expand All @@ -229,6 +233,7 @@ describe('resourceCollection', () => {
duration: (100 * 1e6) as ServerDuration,
method: 'GET',
status_code: 200,
protocol: 'HTTP/1.0',
type: ResourceType.FETCH,
url: 'https://resource.com/valid',
},
Expand Down
11 changes: 11 additions & 0 deletions packages/rum-core/src/domain/resource/resourceCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function processRequest(
duration,
method: request.method,
status_code: request.status,
protocol: request.protocol,
url: isLongDataUrl(request.url) ? sanitizeDataUrl(request.url) : request.url,
},
type: RumEventType.RESOURCE as const,
Expand Down Expand Up @@ -152,6 +153,7 @@ function processResourceEntry(
type,
url: entry.name,
status_code: discardZeroStatus(entry.responseStatus),
protocol: discardEmptyProtocol(entry.nextHopProtocol),
},
type: RumEventType.RESOURCE as const,
_dd: {
Expand Down Expand Up @@ -232,3 +234,12 @@ function computeRequestDuration(pageStateHistory: PageStateHistory, startClocks:
function discardZeroStatus(statusCode: number | undefined): number | undefined {
return statusCode === 0 ? undefined : statusCode
}

/**
* 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
*/
function discardEmptyProtocol(requestProtocol: string | undefined): string | undefined {
return requestProtocol === '' ? undefined : requestProtocol
}
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