Skip to content

Commit

Permalink
Integrate b223572 (#2665) from thomas.lebeau/child-next-sibling into …
Browse files Browse the repository at this point in the history
…staging-13

Co-authored-by: Thomas Lebeau <[email protected]>
  • Loading branch information
dd-mergequeue[bot] and thomas-lebeau authored Mar 25, 2024
2 parents 36b238b + b223572 commit 038202d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/logs/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function startLogsAssembly(

lifeCycle.subscribe(
LifeCycleEventType.RAW_LOG_COLLECTED,
({ rawLogsEvent, messageContext = undefined, savedCommonContext = undefined }) => {
({ rawLogsEvent, messageContext = undefined, savedCommonContext = undefined, domainContext }) => {
const startTime = getRelativeTime(rawLogsEvent.date)
const session = sessionManager.findTrackedSession(startTime)

Expand All @@ -47,7 +47,7 @@ export function startLogsAssembly(
)

if (
configuration.beforeSend?.(log) === false ||
configuration.beforeSend?.(log, domainContext) === false ||
(log.origin !== ErrorSource.AGENT &&
(logRateLimiters[log.status] ?? logRateLimiters['custom']).isLimitReached())
) {
Expand Down
11 changes: 10 additions & 1 deletion packages/logs/src/domain/lifeCycle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractLifeCycle } from '@datadog/browser-core'
import type { Context } from '@datadog/browser-core'
import type { Context, ErrorSource } from '@datadog/browser-core'
import type { LogsEvent } from '../logsEvent.types'
import type { CommonContext, RawLogsEvent } from '../rawLogsEvent.types'

Expand All @@ -16,8 +16,17 @@ interface LifeCycleEventMap {
export const LifeCycle = AbstractLifeCycle<LifeCycleEventMap>
export type LifeCycle = AbstractLifeCycle<LifeCycleEventMap>

export type LogsEventDomainContext<T extends ErrorSource> = T extends typeof ErrorSource.NETWORK
? NetworkLogsEventDomainContext
: never

type NetworkLogsEventDomainContext = {
isAborted: boolean
}

export interface RawLogsEventCollectedData<E extends RawLogsEvent = RawLogsEvent> {
rawLogsEvent: E
messageContext?: object
savedCommonContext?: CommonContext
domainContext?: LogsEventDomainContext<E['origin']>
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('network error collection', () => {

fetchStubManager.whenAllComplete(() => {
expect(rawLogsEvents.length).toEqual(1)
expect(rawLogsEvents[0].domainContext).toEqual({ isAborted: true })
done()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isServerError,
} from '@datadog/browser-core'
import type { LogsConfiguration } from '../configuration'
import type { LifeCycle } from '../lifeCycle'
import type { LifeCycle, LogsEventDomainContext } from '../lifeCycle'
import { LifeCycleEventType } from '../lifeCycle'
import { StatusType } from '../logger'

Expand Down Expand Up @@ -45,6 +45,10 @@ export function startNetworkErrorCollection(configuration: LogsConfiguration, li
}

function onResponseDataAvailable(responseData: unknown) {
const domainContext: LogsEventDomainContext<typeof ErrorSource.NETWORK> = {
isAborted: request.isAborted,
}

lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, {
rawLogsEvent: {
message: `${format(type)} error ${request.method} ${request.url}`,
Expand All @@ -60,6 +64,7 @@ export function startNetworkErrorCollection(configuration: LogsConfiguration, li
status: StatusType.error,
origin: ErrorSource.NETWORK,
},
domainContext,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/logs/src/rawLogsEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface CommonRawLogsEvent {
message: string
status: StatusType
error?: Error
origin: 'network' | 'source' | 'console' | 'logger' | 'agent' | 'report'
origin: ErrorSource
}

export interface RawConsoleLogsEvent extends CommonRawLogsEvent {
Expand Down
3 changes: 3 additions & 0 deletions packages/rum-core/src/domain/requestCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface RequestCompleteEvent {
input?: unknown
init?: RequestInit
error?: Error
isAborted: boolean
}

let nextRequestIndex = 1
Expand Down Expand Up @@ -100,6 +101,7 @@ export function trackXhr(lifeCycle: LifeCycle, configuration: RumConfiguration,
type: RequestType.XHR,
url: context.url,
xhr: context.xhr,
isAborted: context.isAborted,
})
break
}
Expand Down Expand Up @@ -143,6 +145,7 @@ export function trackFetch(lifeCycle: LifeCycle, configuration: RumConfiguration
response: context.response,
init: context.init,
input: context.input,
isAborted: context.isAborted,
})
})
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('resourceCollection', () => {
type: RequestType.XHR,
url: 'https://resource.com/valid',
xhr,
isAborted: false,
})
)

Expand All @@ -117,6 +118,7 @@ describe('resourceCollection', () => {
requestInput: undefined,
requestInit: undefined,
error: undefined,
isAborted: false,
})
})

Expand Down Expand Up @@ -263,6 +265,7 @@ describe('resourceCollection', () => {
response,
input: 'https://resource.com/valid',
init: { headers: { foo: 'bar' } },
isAborted: false,
})
)

Expand All @@ -289,6 +292,7 @@ describe('resourceCollection', () => {
requestInput: 'https://resource.com/valid',
requestInit: { headers: { foo: 'bar' } },
error: undefined,
isAborted: false,
})
})
;[null, undefined, 42, {}].forEach((input: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function processRequest(
requestInput: request.input,
requestInit: request.init,
error: request.error,
isAborted: request.isAborted,
} as RumFetchResourceEventDomainContext | RumXhrResourceEventDomainContext,
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/rum-core/src/domainContext.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export interface RumFetchResourceEventDomainContext {
response?: Response
error?: Error
performanceEntry?: PerformanceEntry
isAborted: boolean
}

export interface RumXhrResourceEventDomainContext {
xhr: XMLHttpRequest
performanceEntry?: PerformanceEntry
isAborted: boolean
}

export interface RumOtherResourceEventDomainContext {
Expand Down

0 comments on commit 038202d

Please sign in to comment.