Skip to content

Commit

Permalink
Collect error report in RUM
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Feb 11, 2022
1 parent c01062c commit 84dd9fc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/tools/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const ErrorSource = {
LOGGER: 'logger',
NETWORK: 'network',
SOURCE: 'source',
REPORT: 'report',
} as const

export enum ErrorHandling {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { RumEventType } from '../../../rawRumEvent.types'
import type { LifeCycle, RawRumEventCollectedData } from '../../lifeCycle'
import { LifeCycleEventType } from '../../lifeCycle'
import type { ForegroundContexts } from '../../foregroundContexts'
import { trackReportError } from './trackReportError'

export interface ProvidedError {
startClocks: ClocksState
Expand All @@ -26,6 +27,7 @@ export function startErrorCollection(lifeCycle: LifeCycle, foregroundContexts: F
const errorObservable = new Observable<RawError>()
trackConsoleError(errorObservable)
trackRuntimeError(errorObservable)
trackReportError(errorObservable)

errorObservable.subscribe((error) => lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error }))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Observable, RawError } from '@datadog/browser-core'
import { clocksNow, ErrorHandling, ErrorSource, initReportObservable, ReportType } from '@datadog/browser-core'

export function trackReportError(errorObservable: Observable<RawError>) {
const subscription = initReportObservable([ReportType.csp_violation, ReportType.intervention]).subscribe(
(reportError) =>
errorObservable.notify({
startClocks: clocksNow(),
message: reportError.message,
stack: reportError.stack,
source: ErrorSource.REPORT,
handling: ErrorHandling.HANDLED,
})
)

return {
stop: () => {
subscription.unsubscribe()
},
}
}

0 comments on commit 84dd9fc

Please sign in to comment.