Skip to content

Commit

Permalink
Merge branch 'main' into yannick.adam/RUMF-1470-Remove-sanitize-featu…
Browse files Browse the repository at this point in the history
…re-flag
  • Loading branch information
yannickadam committed Apr 24, 2023
2 parents 265629b + fbcfb8a commit 8bb5311
Show file tree
Hide file tree
Showing 46 changed files with 535 additions and 539 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variables:
CURRENT_STAGING: staging-16
CURRENT_STAGING: staging-17
APP: 'browser-sdk'
CURRENT_CI_IMAGE: 45
BUILD_STABLE_REGISTRY: '486234852809.dkr.ecr.us-east-1.amazonaws.com'
Expand Down
14 changes: 4 additions & 10 deletions packages/core/src/domain/error/error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import type { StackTrace } from '../tracekit'
import { clocksNow } from '../../tools/utils/timeUtils'
import type { RawErrorCause, ErrorWithCause } from './error'
import {
createHandlingStack,
computeRawError,
getFileFromStackTraceString,
flattenErrorCauses,
ErrorSource,
ErrorHandling,
} from './error'
import { createHandlingStack, computeRawError, getFileFromStackTraceString, flattenErrorCauses } from './error'
import type { RawErrorCause, ErrorWithCause } from './error.types'
import { ErrorHandling, ErrorSource, NonErrorPrefix } from './error.types'

describe('computeRawError', () => {
const NOT_COMPUTED_STACK_TRACE: StackTrace = { name: undefined, message: undefined, stack: [] } as any
const DEFAULT_RAW_ERROR_PARAMS = {
startClocks: clocksNow(),
nonErrorPrefix: 'Uncaught',
nonErrorPrefix: NonErrorPrefix.UNCAUGHT,
source: ErrorSource.CUSTOM,
}

Expand Down
46 changes: 3 additions & 43 deletions packages/core/src/domain/error/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,17 @@ import { sanitize } from '../../tools/serialisation/sanitize'
import type { ClocksState } from '../../tools/utils/timeUtils'
import { noop } from '../../tools/utils/functionUtils'
import { jsonStringify } from '../../tools/serialisation/jsonStringify'
import type { ErrorSource, ErrorHandling, RawError, RawErrorCause, ErrorWithCause, NonErrorPrefix } from './error.types'

export const NO_ERROR_STACK_PRESENT_MESSAGE = 'No stack, consider using an instance of Error'
export const PROVIDED_ERROR_MESSAGE_PREFIX = 'Provided'

export interface ErrorWithCause extends Error {
cause?: Error
}

export type RawErrorCause = {
message: string
source: string
type?: string
stack?: string
}

export interface RawError {
startClocks: ClocksState
message: string
type?: string
stack?: string
source: ErrorSource
originalError?: unknown
handling?: ErrorHandling
handlingStack?: string
causes?: RawErrorCause[]
}

export const ErrorSource = {
AGENT: 'agent',
CONSOLE: 'console',
CUSTOM: 'custom',
LOGGER: 'logger',
NETWORK: 'network',
SOURCE: 'source',
REPORT: 'report',
} as const

export const enum ErrorHandling {
HANDLED = 'handled',
UNHANDLED = 'unhandled',
}

export type ErrorSource = (typeof ErrorSource)[keyof typeof ErrorSource]

type RawErrorParams = {
stackTrace?: StackTrace
originalError: unknown

handlingStack?: string
startClocks: ClocksState
nonErrorPrefix: string
nonErrorPrefix: NonErrorPrefix
source: ErrorSource
handling: ErrorHandling
}
Expand All @@ -76,7 +36,7 @@ export function computeRawError({
handling,
originalError,
message: `${nonErrorPrefix} ${jsonStringify(sanitize(originalError))!}`,
stack: 'No stack, consider using an instance of Error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
handlingStack,
type: stackTrace && stackTrace.name,
}
Expand Down
46 changes: 46 additions & 0 deletions packages/core/src/domain/error/error.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { ClocksState } from '../../tools/utils/timeUtils'

export interface ErrorWithCause extends Error {
cause?: Error
}

export type RawErrorCause = {
message: string
source: string
type?: string
stack?: string
}

export interface RawError {
startClocks: ClocksState
message: string
type?: string
stack?: string
source: ErrorSource
originalError?: unknown
handling?: ErrorHandling
handlingStack?: string
causes?: RawErrorCause[]
}

export const ErrorSource = {
AGENT: 'agent',
CONSOLE: 'console',
CUSTOM: 'custom',
LOGGER: 'logger',
NETWORK: 'network',
SOURCE: 'source',
REPORT: 'report',
} as const

export const enum NonErrorPrefix {
UNCAUGHT = 'Uncaught',
PROVIDED = 'Provided',
}

export const enum ErrorHandling {
HANDLED = 'handled',
UNHANDLED = 'unhandled',
}

export type ErrorSource = (typeof ErrorSource)[keyof typeof ErrorSource]
5 changes: 3 additions & 2 deletions packages/core/src/domain/error/trackRuntimeError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Observable } from '../../tools/observable'
import type { RawError } from './error'
import { NO_ERROR_STACK_PRESENT_MESSAGE } from './error'
import { trackRuntimeError } from './trackRuntimeError'
import type { RawError } from './error.types'

describe('runtime error tracker', () => {
const ERROR_MESSAGE = 'foo'
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('runtime error tracker', () => {
setTimeout(() => {
const collectedError = notifyError.calls.mostRecent().args[0] as RawError
expect(collectedError.message).toEqual('Uncaught {"foo":"bar"}')
expect(collectedError.stack).toEqual('No stack, consider using an instance of Error')
expect(collectedError.stack).toEqual(NO_ERROR_STACK_PRESENT_MESSAGE)
done()
}, 100)
})
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/domain/error/trackRuntimeError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Observable } from '../../tools/observable'
import { clocksNow } from '../../tools/utils/timeUtils'
import { startUnhandledErrorCollection } from '../tracekit'
import { ErrorSource, computeRawError, ErrorHandling } from './error'
import type { RawError } from './error'
import { computeRawError } from './error'
import type { RawError } from './error.types'
import { ErrorHandling, ErrorSource, NonErrorPrefix } from './error.types'

export function trackRuntimeError(errorObservable: Observable<RawError>) {
return startUnhandledErrorCollection((stackTrace, originalError) => {
Expand All @@ -11,7 +12,7 @@ export function trackRuntimeError(errorObservable: Observable<RawError>) {
stackTrace,
originalError,
startClocks: clocksNow(),
nonErrorPrefix: 'Uncaught',
nonErrorPrefix: NonErrorPrefix.UNCAUGHT,
source: ErrorSource.SOURCE,
handling: ErrorHandling.UNHANDLED,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Clock } from '../../../test'
import { mockClock } from '../../../test'
import type { RawError } from '../error/error'
import type { RelativeTime } from '../../tools/utils/timeUtils'
import { relativeToClocks, resetNavigationStart, ONE_MINUTE } from '../../tools/utils/timeUtils'
import { noop } from '../../tools/utils/functionUtils'
import type { RawError } from '../error/error.types'
import { createEventRateLimiter } from './createEventRateLimiter'
import type { EventRateLimiter } from './createEventRateLimiter'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { setTimeout } from '../../tools/timer'
import type { RawError } from '../error/error'
import { ErrorSource } from '../error/error'
import { clocksNow, ONE_MINUTE } from '../../tools/utils/timeUtils'
import type { RawError } from '../error/error.types'
import { ErrorSource } from '../error/error.types'

export type EventRateLimiter = ReturnType<typeof createEventRateLimiter>

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/domain/telemetry/telemetry.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { StackTrace } from '@datadog/browser-core'
import { NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error'
import { callMonitored } from '../../tools/monitor'
import type { ExperimentalFeature } from '../../tools/experimentalFeatures'
import { resetExperimentalFeatures, addExperimentalFeatures } from '../../tools/experimentalFeatures'
Expand Down Expand Up @@ -161,7 +162,7 @@ describe('formatError', () => {
expect(formatError('message')).toEqual({
message: 'Uncaught "message"',
error: {
stack: 'Not an instance of error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
},
})
})
Expand All @@ -170,7 +171,7 @@ describe('formatError', () => {
expect(formatError({ foo: 'bar' })).toEqual({
message: 'Uncaught {"foo":"bar"}',
error: {
stack: 'Not an instance of error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
},
})
})
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/domain/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Context } from '../../tools/serialisation/context'
import { ConsoleApiName } from '../../tools/display'
import { toStackTraceString } from '../error/error'
import { toStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error'
import { getExperimentalFeatures } from '../../tools/experimentalFeatures'
import type { Configuration } from '../configuration'
import { INTAKE_SITE_STAGING, INTAKE_SITE_US1_FED } from '../configuration'
Expand All @@ -14,6 +14,7 @@ import { startsWith, arrayFrom, includes, assign } from '../../tools/utils/polyf
import { performDraw } from '../../tools/utils/numberUtils'
import { jsonStringify } from '../../tools/serialisation/jsonStringify'
import { combine } from '../../tools/mergeInto'
import { NonErrorPrefix } from '../error/error.types'
import type { TelemetryEvent } from './telemetryEvent.types'
import type { RawTelemetryConfiguration, RawTelemetryEvent } from './rawTelemetryEvent.types'
import { StatusType, TelemetryType } from './rawTelemetryEvent.types'
Expand Down Expand Up @@ -181,9 +182,9 @@ export function formatError(e: unknown) {
}
return {
error: {
stack: 'Not an instance of error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
},
message: `Uncaught ${jsonStringify(e)!}`,
message: `${NonErrorPrefix.UNCAUGHT} ${jsonStringify(e)!}`,
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/domain/telemetry/telemetryEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ export type TelemetryConfigurationEvent = CommonTelemetryProperties & {
* The upload frequency of batches (in milliseconds)
*/
batch_upload_frequency?: number
/**
* The version of React used in a ReactNative application
*/
react_version?: string
/**
* The version of ReactNative used in a ReactNative application
*/
react_native_version?: string
/**
* The version of Dart used in a Flutter application
*/
dart_version?: string
[k: string]: unknown
}
[k: string]: unknown
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,13 @@ export { runOnReadyState } from './browser/runOnReadyState'
export { getZoneJsOriginalValue } from './tools/getZoneJsOriginalValue'
export { instrumentMethod, instrumentMethodAndCallOriginal, instrumentSetter } from './tools/instrumentMethod'
export {
ErrorSource,
ErrorHandling,
computeRawError,
createHandlingStack,
RawError,
RawErrorCause,
ErrorWithCause,
toStackTraceString,
getFileFromStackTraceString,
NO_ERROR_STACK_PRESENT_MESSAGE,
PROVIDED_ERROR_MESSAGE_PREFIX,
} from './domain/error/error'
export { NonErrorPrefix } from './domain/error/error.types'
export { Context, ContextArray, ContextValue } from './tools/serialisation/context'
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie'
export { initXhrObservable, XhrCompleteContext, XhrStartContext } from './browser/xhrObservable'
Expand Down Expand Up @@ -126,3 +121,8 @@ export * from './tools/utils/stringUtils'
export * from './tools/matchOption'
export * from './tools/utils/responseUtils'
export * from './tools/utils/typeUtils'
export { ErrorHandling } from './domain/error/error.types'
export { ErrorSource } from './domain/error/error.types'
export { RawError } from './domain/error/error.types'
export { RawErrorCause } from './domain/error/error.types'
export { ErrorWithCause } from './domain/error/error.types'
2 changes: 0 additions & 2 deletions packages/core/src/tools/experimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export enum ExperimentalFeature {
PAGEHIDE = 'pagehide',
FEATURE_FLAGS = 'feature_flags',
RESOURCE_PAGE_STATES = 'resource_page_states',
CLICKMAP = 'clickmap',
COLLECT_FLUSH_REASON = 'collect_flush_reason',
REPLAY_JSON_PAYLOAD = 'replay_json_payload',
}

const enabledExperimentalFeatures: Set<ExperimentalFeature> = new Set()
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transport/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { EndpointBuilder } from '../domain/configuration'
import { addTelemetryError } from '../domain/telemetry'
import type { Context } from '../tools/serialisation/context'
import { monitor } from '../tools/monitor'
import type { RawError } from '../domain/error/error'
import { addEventListener } from '../browser/addEventListener'
import type { RawError } from '../domain/error/error.types'
import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'
import type { FlushReason } from './flushController'

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transport/sendWithRetryStrategy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockClock, restoreNavigatorOnLine, setNavigatorOnLine } from '../../test'
import type { Clock } from '../../test'
import { ErrorSource } from '../domain/error/error'
import { ErrorSource } from '../domain/error/error.types'
import type { RetryState } from './sendWithRetryStrategy'
import {
newRetryState,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/transport/sendWithRetryStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { EndpointType } from '../domain/configuration'
import { setTimeout } from '../tools/timer'
import type { RawError } from '../domain/error/error'
import { clocksNow, ONE_MINUTE, ONE_SECOND } from '../tools/utils/timeUtils'
import { ErrorSource } from '../domain/error/error'
import { ONE_MEBI_BYTE, ONE_KIBI_BYTE } from '../tools/utils/byteUtils'
import { isServerError } from '../tools/utils/responseUtils'
import type { RawError } from '../domain/error/error.types'
import { ErrorSource } from '../domain/error/error.types'
import type { Payload, HttpResponse } from './httpRequest'

export const MAX_ONGOING_BYTES_COUNT = 80 * ONE_KIBI_BYTE
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transport/startBatchWithReplica.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Configuration, EndpointBuilder } from '../domain/configuration'
import type { RawError } from '../domain/error/error'
import type { Context } from '../tools/serialisation/context'
import type { Observable } from '../tools/observable'
import type { PageExitEvent } from '../browser/pageExitObservable'
import type { RawError } from '../domain/error/error.types'
import { Batch } from './batch'
import { createHttpRequest } from './httpRequest'
import { createFlushController } from './flushController'
Expand Down
4 changes: 2 additions & 2 deletions packages/logs/src/domain/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
clocksNow,
computeRawError,
ErrorHandling,
PROVIDED_ERROR_MESSAGE_PREFIX,
computeStackTrace,
CustomerDataType,
assign,
Expand All @@ -12,6 +11,7 @@ import {
ErrorSource,
monitored,
sanitize,
NonErrorPrefix,
} from '@datadog/browser-core'

import type { LogsEvent } from '../logsEvent.types'
Expand Down Expand Up @@ -67,7 +67,7 @@ export class Logger {
const rawError = computeRawError({
stackTrace,
originalError: error,
nonErrorPrefix: PROVIDED_ERROR_MESSAGE_PREFIX,
nonErrorPrefix: NonErrorPrefix.PROVIDED,
source: ErrorSource.LOGGER,
handling: ErrorHandling.HANDLED,
startClocks: clocksNow(),
Expand Down
Loading

0 comments on commit 8bb5311

Please sign in to comment.