Skip to content
Merged
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
10 changes: 10 additions & 0 deletions packages/otlp-ingester/src/fingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ const LONG_HEX_RE = /\b[0-9a-f]{8,}\b/gi;
// template too, or per-value messages fragment into separate fingerprints.
const NUMBER_RE = /\b\d+(\.\d+)?/g;
const QUOTED_RE = /(["'`])(?:\\.|(?!\1).)*\1/g;
// `\b` never fires between `_` and a digit (both are word chars), so
// underscore-glued ids — "prj_1013", "user_42", "order_9f3ac2d144" — escape
// NUMBER_RE/LONG_HEX_RE entirely and fragment one defect into an issue per
// id. Template the value after the underscore explicitly. (Letter-glued
// digits like "sha256"/"utf8" stay literal on purpose — those are usually
// meaningful tokens, not per-entity ids.)
const UNDERSCORE_HEX_RE = /_[0-9a-f]{8,}\b/gi;
const UNDERSCORE_NUMBER_RE = /_\d+(\.\d+)?\b/g;

export function normalizeMessage(message: string): string {
return message
.slice(0, 500)
.replace(QUOTED_RE, "<str>")
.replace(UUID_RE, "<uuid>")
.replace(LONG_HEX_RE, "<hex>")
.replace(UNDERSCORE_HEX_RE, "_<hex>")
.replace(UNDERSCORE_NUMBER_RE, "_<n>")
.replace(NUMBER_RE, "<n>")
.replace(/\s+/g, " ")
.trim();
Expand Down
Loading