Skip to content

Commit

Permalink
add protocol for xhr and fetch request
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanGaignault committed Oct 24, 2024
1 parent 86cfedc commit 10cc941
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/rum-core/src/domain/requestCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ 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 @@ -102,7 +102,6 @@ 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 @@ -118,7 +117,7 @@ describe('resourceCollection', () => {
duration: (100 * 1e6) as ServerDuration,
method: 'GET',
status_code: 200,
protocol: 'HTTP/1.0',
protocol: undefined,
type: ResourceType.XHR,
url: 'https://resource.com/valid',
},
Expand Down Expand Up @@ -215,7 +214,6 @@ 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 @@ -233,7 +231,7 @@ describe('resourceCollection', () => {
duration: (100 * 1e6) as ServerDuration,
method: 'GET',
status_code: 200,
protocol: 'HTTP/1.0',
protocol: undefined,
type: ResourceType.FETCH,
url: 'https://resource.com/valid',
},
Expand Down
14 changes: 3 additions & 11 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,7 +105,7 @@ function processRequest(
duration,
method: request.method,
status_code: request.status,
protocol: request.protocol,
protocol: matchingTiming && computeResourceEntryProtocol(matchingTiming),
url: isLongDataUrl(request.url) ? sanitizeDataUrl(request.url) : request.url,
},
type: RumEventType.RESOURCE as const,
Expand Down Expand Up @@ -153,7 +154,7 @@ function processResourceEntry(
type,
url: entry.name,
status_code: discardZeroStatus(entry.responseStatus),
protocol: discardEmptyProtocol(entry.nextHopProtocol),
protocol: computeResourceEntryProtocol(entry),
},
type: RumEventType.RESOURCE as const,
_dd: {
Expand Down Expand Up @@ -234,12 +235,3 @@ 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
}
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

0 comments on commit 10cc941

Please sign in to comment.