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

[FIX] Allow using a custom error fingerprint in simple error logs #796

Conversation

marco-saia-datadog
Copy link
Member

What does this PR do?

Allows passing a custom error fingerprint to error logs that consist of only a message and an optional context.

- DdLogs.error(message: string, context?: object)
+ DdLogs.error(message: string, context?: object, fingerprint?: string)

Motivation

It is currently possible to use a custom error fingerprint for logs with error, but not for simple logs that only have a message and an optional context.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@marco-saia-datadog marco-saia-datadog requested a review from a team as a code owner February 11, 2025 10:23
@marco-saia-datadog marco-saia-datadog marked this pull request as draft February 11, 2025 10:35
@marco-saia-datadog marco-saia-datadog force-pushed the marcosaia/fix/simple-error-logs-fingerprint branch from 9065fc7 to 960814f Compare February 12, 2025 13:29
return logEvent;
});

console.error('test-error');

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 about console statements and leave them in production code. There is no need to pollute production builds with debugging statements.

View in Datadog  Leave us feedback  Documentation

};

export const formatRawLogToNativeEvent = (
rawLog: RawLog | RawLogWithError
): NativeLog | NativeLogWithError => {
if ((rawLog as RawLogWithError).fingerprint) {
(rawLog.context as any)[

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Unsafe assignment of an `any` value. (...read more)

The any type in TypeScript is dangerously broad, leading to unexpected behavior. Using any should be avoided.

View in Datadog  Leave us feedback  Documentation

return (this.context as any)[DdAttributes.errorFingerprint] as string;
}
public set fingerprint(value: string | undefined) {
(this.context as any)[DdAttributes.errorFingerprint] = value;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Unsafe assignment of an `any` value. (...read more)

The any type in TypeScript is dangerously broad, leading to unexpected behavior. Using any should be avoided.

View in Datadog  Leave us feedback  Documentation

attributes?: object | undefined;

public get fingerprint(): string | undefined {
return (this.context as any)[DdAttributes.errorFingerprint] as string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Unsafe assignment of an `any` value. (...read more)

The any type in TypeScript is dangerously broad, leading to unexpected behavior. Using any should be avoided.

View in Datadog  Leave us feedback  Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant