Skip to content

Commit

Permalink
👌 mutualize fingerprint sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Apr 28, 2023
1 parent 66c3c87 commit 30980eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/domain/console/consoleObservable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computeStackTrace } from '../tracekit'
import { createHandlingStack, formatErrorMessage, toStackTraceString, isErrorWithFingerprint } from '../error/error'
import { createHandlingStack, formatErrorMessage, toStackTraceString, tryToGetFingerprint } from '../error/error'
import { mergeObservables, Observable } from '../../tools/observable'
import { ConsoleApiName } from '../../tools/display'
import { callMonitored } from '../../tools/monitor'
Expand Down Expand Up @@ -63,7 +63,7 @@ function buildConsoleLog(params: unknown[], api: ConsoleApiName, handlingStack:
if (api === ConsoleApiName.error) {
const firstErrorParam = find(params, (param: unknown): param is Error => param instanceof Error)
stack = firstErrorParam ? toStackTraceString(computeStackTrace(firstErrorParam)) : undefined
fingerprint = isErrorWithFingerprint(firstErrorParam) ? String(firstErrorParam.dd_fingerprint) : undefined
fingerprint = tryToGetFingerprint(firstErrorParam)
message = `console error: ${message}`
}

Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/domain/error/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function computeRawError({
: NO_ERROR_STACK_PRESENT_MESSAGE
const causes = isErrorInstance ? flattenErrorCauses(originalError as ErrorWithCause, source) : undefined
const type = stackTrace?.name
const fingerprint = isErrorWithFingerprint(originalError) ? String(originalError.dd_fingerprint) : undefined
const fingerprint = tryToGetFingerprint(originalError)

return {
startClocks,
Expand All @@ -67,8 +67,10 @@ function hasUsableStack(isErrorInstance: boolean, stackTrace?: StackTrace): stac
return stackTrace.stack.length > 0 && (stackTrace.stack.length > 1 || stackTrace.stack[0].url !== undefined)
}

export function isErrorWithFingerprint(error: unknown): error is { dd_fingerprint: unknown } {
return error instanceof Error && 'dd_fingerprint' in error
export function tryToGetFingerprint(originalError: unknown) {
return originalError instanceof Error && 'dd_fingerprint' in originalError
? String(originalError.dd_fingerprint)
: undefined
}

export function toStackTraceString(stack: StackTrace) {
Expand Down

0 comments on commit 30980eb

Please sign in to comment.