Skip to content

Commit

Permalink
Integrate d5a483d (#2587) from roman/responseStatus into staging-06
Browse files Browse the repository at this point in the history
Co-authored-by: roman.gaignault <roman.gaignault@datadoghq.com>
  • Loading branch information
dd-mergequeue[bot] and RomanGaignault authored Feb 5, 2024
2 parents 8fd5da3 + d5a483d commit 51d8f1e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/rum-core/src/browser/performanceCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export enum RumPerformanceEntryType {
export interface RumPerformanceResourceTiming {
entryType: RumPerformanceEntryType.RESOURCE
initiatorType: string
responseStatus?: number
name: string
startTime: RelativeTime
duration: Duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('resourceCollection', () => {
url: 'https://resource.com/valid',
download: jasmine.any(Object),
first_byte: jasmine.any(Object),
status_code: 200,
},
type: RumEventType.RESOURCE,
_dd: {
Expand Down Expand Up @@ -315,6 +316,13 @@ describe('resourceCollection', () => {
)
})

it('should discard 0 status code', () => {
const { lifeCycle, rawRumEvents } = setupBuilder.build()
const performanceEntry = createPerformanceEntry(RumPerformanceEntryType.RESOURCE, { responseStatus: 0 })
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, [performanceEntry])
expect((rawRumEvents[0].rawRumEvent as RawRumResourceEvent).resource.status_code).toBe(undefined)
})

describe('tracing info', () => {
it('should be processed from traced initial document', () => {
const { lifeCycle, rawRumEvents } = setupBuilder.build()
Expand Down
10 changes: 9 additions & 1 deletion packages/rum-core/src/domain/resource/resourceCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ function processRequest(
correspondingTimingOverrides,
pageStateInfo
)

return {
startTime: startClocks.relative,
rawRumEvent: resourceEvent,
Expand Down Expand Up @@ -142,6 +141,7 @@ function processResourceEntry(
id: generateUUID(),
type,
url: entry.name,
status_code: discardZeroStatus(entry.responseStatus),
},
type: RumEventType.RESOURCE as const,
_dd: {
Expand Down Expand Up @@ -235,3 +235,11 @@ function computeRequestDuration(pageStateHistory: PageStateHistory, startClocks:

return !requestCrossedFrozenState ? toServerDuration(duration) : undefined
}

/**
* The status is 0 for cross origin resources without CORS headers, so the status is meaningless and we shouldn't report it
* https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes
*/
function discardZeroStatus(statusCode: number | undefined): number | undefined {
return statusCode === 0 ? undefined : statusCode
}
1 change: 1 addition & 0 deletions packages/rum-core/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export function createPerformanceEntry<T extends RumPerformanceEntryType>(
responseStart: 200 as RelativeTime,
secureConnectionStart: 200 as RelativeTime,
startTime: 200 as RelativeTime,
responseStatus: 200,
},
overrides
) as EntryTypeToReturnType[T]
Expand Down

0 comments on commit 51d8f1e

Please sign in to comment.