-
Notifications
You must be signed in to change notification settings - Fork 46
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
[FIX] Allow using a custom error fingerprint in simple error logs #796
Closed
marco-saia-datadog
wants to merge
1
commit into
develop
from
marcosaia/fix/simple-error-logs-fingerprint
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,12 @@ | |
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
import { DdAttributes } from '../rum/DdAttributes'; | ||
import type { Attributes } from '../sdk/AttributesSingleton/types'; | ||
import { EventMapper } from '../sdk/EventMappers/EventMapper'; | ||
import type { UserInfo } from '../sdk/UserInfoSingleton/types'; | ||
|
||
import { InternalLogEvent } from './types'; | ||
import type { | ||
LogEvent, | ||
LogEventMapper, | ||
|
@@ -20,12 +22,17 @@ import type { | |
export const formatLogEventToNativeLog = ( | ||
logEvent: LogEvent | ||
): NativeLog | NativeLogWithError => { | ||
return logEvent; | ||
return new InternalLogEvent(logEvent); | ||
}; | ||
|
||
export const formatRawLogToNativeEvent = ( | ||
rawLog: RawLog | RawLogWithError | ||
): NativeLog | NativeLogWithError => { | ||
if ((rawLog as RawLogWithError).fingerprint) { | ||
(rawLog.context as any)[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
DdAttributes.errorFingerprint | ||
] = (rawLog as RawLogWithError).fingerprint; | ||
} | ||
return rawLog; | ||
}; | ||
|
||
|
@@ -36,11 +43,11 @@ export const formatRawLogToLogEvent = ( | |
attributes: Attributes; | ||
} | ||
): LogEvent => { | ||
return { | ||
return new InternalLogEvent({ | ||
...rawLog, | ||
userInfo: additionalInformation.userInfo, | ||
attributes: additionalInformation.attributes | ||
}; | ||
}); | ||
}; | ||
|
||
export const generateEventMapper = ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
import { DdAttributes } from '../rum/DdAttributes'; | ||
import type { ErrorSource } from '../rum/types'; | ||
import type { UserInfo } from '../sdk/UserInfoSingleton/types'; | ||
|
||
|
@@ -91,6 +92,38 @@ export type LogEvent = { | |
readonly attributes?: object; | ||
}; | ||
|
||
export class InternalLogEvent implements LogEvent { | ||
message: string; | ||
context: object; | ||
errorKind?: string | undefined; | ||
errorMessage?: string | undefined; | ||
stacktrace?: string | undefined; | ||
source?: ErrorSource | undefined; | ||
status: LogStatus; | ||
userInfo: UserInfo; | ||
attributes?: object | undefined; | ||
|
||
public get fingerprint(): string | undefined { | ||
return (this.context as any)[DdAttributes.errorFingerprint] as string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
public set fingerprint(value: string | undefined) { | ||
(this.context as any)[DdAttributes.errorFingerprint] = value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
constructor(props: LogEvent) { | ||
this.message = props.message; | ||
this.context = props.context; | ||
this.errorKind = props.errorKind; | ||
this.errorMessage = props.errorMessage; | ||
this.stacktrace = props.stacktrace; | ||
this.fingerprint = props.fingerprint; | ||
this.status = props.status; | ||
this.source = props.source; | ||
this.userInfo = props.userInfo; | ||
this.attributes = props.attributes; | ||
} | ||
} | ||
|
||
export type LogEventMapper = (logEvent: LogEvent) => LogEvent | null; | ||
|
||
export type LogArguments = [message: string, context?: object]; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Code Quality Violation
Unexpected console statement. (...read more)
Debugging with
console
is not considered a bad practice, but it's easy to forget aboutconsole
statements and leave them in production code. There is no need to pollute production builds with debugging statements.