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

💥 remove addError 'source' argument #936

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 1 addition & 16 deletions packages/rum-core/src/boot/rumPublicApi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorSource, ONE_SECOND, RelativeTime, getTimeStamp, display, TimeStamp } from '@datadog/browser-core'
import { ONE_SECOND, RelativeTime, getTimeStamp, display, TimeStamp } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../test/specHelper'
import { ActionType } from '../rawRumEvent.types'
import { makeRumPublicApi, RumPublicApi, RumInitConfiguration, StartRum } from './rumPublicApi'
Expand Down Expand Up @@ -280,27 +280,12 @@ describe('rum public api', () => {
context: undefined,
error: new Error('foo'),
handlingStack: jasmine.any(String),
source: ErrorSource.CUSTOM,
startClocks: jasmine.any(Object),
},
{ context: {}, user: {} },
])
})

it('allows setting an ErrorSource', () => {
rumPublicApi.init(DEFAULT_INIT_CONFIGURATION)
rumPublicApi.addError(new Error('foo'), undefined, ErrorSource.SOURCE)
expect(addErrorSpy.calls.argsFor(0)[0].source).toBe(ErrorSource.SOURCE)
})

it('fallbacks to ErrorSource.CUSTOM if an invalid source is given', () => {
const displaySpy = spyOn(display, 'error')
rumPublicApi.init(DEFAULT_INIT_CONFIGURATION)
rumPublicApi.addError(new Error('foo'), undefined, 'invalid' as any)
expect(addErrorSpy.calls.argsFor(0)[0].source).toBe(ErrorSource.CUSTOM)
expect(displaySpy).toHaveBeenCalledWith("DD_RUM.addError: Invalid source 'invalid'")
})

it('should generate a handling stack', () => {
rumPublicApi.init(DEFAULT_INIT_CONFIGURATION)
function triggerError() {
Expand Down
12 changes: 1 addition & 11 deletions packages/rum-core/src/boot/rumPublicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Context,
createContextManager,
deepClone,
ErrorSource,
isPercentage,
makePublicApi,
monitor,
Expand All @@ -20,7 +19,6 @@ import {
callMonitored,
createHandlingStack,
} from '@datadog/browser-core'
import { ProvidedSource } from '../domain/rumEventsCollection/error/errorCollection'
import { RumEventDomainContext } from '../domainContext.types'
import { CommonContext, User, ActionType } from '../rawRumEvent.types'
import { RumEvent } from '../rumEvent.types'
Expand Down Expand Up @@ -161,21 +159,13 @@ export function makeRumPublicApi<C extends RumInitConfiguration>(startRumImpl: S
rumPublicApi.addAction(name, context as Context)
},

addError: (error: unknown, context?: object, source: ProvidedSource = ErrorSource.CUSTOM) => {
addError: (error: unknown, context?: object) => {
const handlingStack = createHandlingStack()
callMonitored(() => {
let checkedSource: ProvidedSource
if (source === ErrorSource.CUSTOM || source === ErrorSource.NETWORK || source === ErrorSource.SOURCE) {
checkedSource = source
} else {
display.error(`DD_RUM.addError: Invalid source '${source as string}'`)
checkedSource = ErrorSource.CUSTOM
}
addErrorStrategy({
error,
handlingStack,
context: deepClone(context as Context),
source: checkedSource,
startClocks: clocksNow(),
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('error collection', () => {
addError({
error,
handlingStack: 'Error: handling foo',
source: ErrorSource.CUSTOM,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
})

Expand Down Expand Up @@ -69,7 +68,6 @@ describe('error collection', () => {
context: { foo: 'bar' },
error: new Error('foo'),
handlingStack: 'Error: handling foo',
source: ErrorSource.CUSTOM,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
})
expect(rawRumEvents[0].customerContext).toEqual({
Expand All @@ -83,7 +81,6 @@ describe('error collection', () => {
{
error: new Error('foo'),
handlingStack: 'Error: handling foo',
source: ErrorSource.CUSTOM,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
},
{ context: { foo: 'bar' }, user: {} }
Expand All @@ -99,7 +96,6 @@ describe('error collection', () => {
{
error: new Error('foo'),
handlingStack: 'Error: handling foo',
source: ErrorSource.CUSTOM,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
},
{ context: {}, user: { id: 'foo' } }
Expand All @@ -113,7 +109,6 @@ describe('error collection', () => {
const { rawRumEvents } = setupBuilder.build()
addError({
error: { foo: 'bar' },
source: ErrorSource.CUSTOM,
handlingStack: 'Error: handling foo',
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Context,
formatUnknownError,
RawError,
ErrorSource,
ClocksState,
generateUUID,
ErrorHandling,
Expand All @@ -20,12 +21,9 @@ export interface ProvidedError {
startClocks: ClocksState
error: unknown
context?: Context
source: ProvidedSource
handlingStack: string
}

export type ProvidedSource = 'custom' | 'network' | 'source'

export function startErrorCollection(
lifeCycle: LifeCycle,
configuration: Configuration,
Expand Down Expand Up @@ -54,10 +52,10 @@ export function doStartErrorCollection(lifeCycle: LifeCycle, foregroundContexts:

return {
addError: (
{ error, handlingStack, startClocks, context: customerContext, source }: ProvidedError,
{ error, handlingStack, startClocks, context: customerContext }: ProvidedError,
savedCommonContext?: CommonContext
) => {
const rawError = computeRawError(error, handlingStack, startClocks, source)
const rawError = computeRawError(error, handlingStack, startClocks)
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
customerContext,
savedCommonContext,
Expand All @@ -67,16 +65,11 @@ export function doStartErrorCollection(lifeCycle: LifeCycle, foregroundContexts:
}
}

function computeRawError(
error: unknown,
handlingStack: string,
startClocks: ClocksState,
source: ProvidedSource
): RawError {
function computeRawError(error: unknown, handlingStack: string, startClocks: ClocksState): RawError {
const stackTrace = error instanceof Error ? computeStackTrace(error) : undefined
return {
startClocks,
source,
source: ErrorSource.CUSTOM,
originalError: error,
...formatUnknownError(stackTrace, error, 'Provided', handlingStack),
handling: ErrorHandling.HANDLED,
Expand Down
1 change: 0 additions & 1 deletion packages/rum-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export {
makeRumPublicApi,
StartRum,
} from './boot/rumPublicApi'
export { ProvidedSource } from './domain/rumEventsCollection/error/errorCollection'
export {
RumEvent,
RumActionEvent,
Expand Down
1 change: 0 additions & 1 deletion packages/rum-recorder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
export { datadogRum } from './boot/recorder.entry'
export {
CommonProperties,
ProvidedSource,
RumInitConfiguration,
RumUserConfiguration,
// Events
Expand Down
1 change: 0 additions & 1 deletion packages/rum/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
export { datadogRum } from './boot/rum.entry'
export {
CommonProperties,
ProvidedSource,
RumPublicApi as RumGlobal,
RumInitConfiguration,
RumUserConfiguration,
Expand Down