Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions .changeset/fingerprint-aggregation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@iqai/alert-logger": patch
---

fix: improve default fingerprint aggregation to reduce alert noise

- Normalize titles with the same rules used for messages (UUIDs, hex addresses, timestamps, numbers) so dynamic values in titles don't split fingerprints.
- Reduce default `stackDepth` from 3 to 1 so the same error from different callers groups into a single aggregation stream. Users can restore the previous behavior with `fingerprint: { stackDepth: 3 }`.
27 changes: 26 additions & 1 deletion src/core/fingerprinter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ describe('fingerprint', () => {
expect(a).not.toBe(b)
})

it('groups same error from different callers with default stackDepth', () => {
const stackA = [
'Error: test',
' at throwSite (/app/src/shared.ts:10:5)',
' at callerA (/app/src/a.ts:20:3)',
' at handlerA (/app/src/routes-a.ts:30:1)',
].join('\n')
const stackB = [
'Error: test',
' at throwSite (/app/src/shared.ts:10:5)',
' at callerB (/app/src/b.ts:40:3)',
' at handlerB (/app/src/routes-b.ts:50:1)',
].join('\n')

const a = fingerprint('E', 'test', makeErrorWithStack(stackA), cfg)
const b = fingerprint('E', 'test', makeErrorWithStack(stackB), cfg)
expect(a).toBe(b)
})

it('includes file, line, and column in stack key', () => {
const stackA = ['Error: test', ' at fn (/app/src/index.ts:10:5)'].join('\n')
const stackB = ['Error: test', ' at fn (/app/src/index.ts:10:99)'].join('\n')
Expand All @@ -205,10 +224,16 @@ describe('fingerprint', () => {
expect(hash).toMatch(/^[0-9a-f]{32}$/)
})

it('uses title as errorName when error is undefined', () => {
it('uses normalized title as errorName when error is undefined', () => {
const a = fingerprint('TitleA', 'same msg', undefined, cfg)
const b = fingerprint('TitleB', 'same msg', undefined, cfg)
expect(a).not.toBe(b)
})

it('normalizes dynamic parts in title when error is undefined', () => {
const a = fingerprint('GET /users/0xABC123DEF/positions', 'table missing', undefined, cfg)
const b = fingerprint('GET /users/0xDEF456ABC/positions', 'table missing', undefined, cfg)
expect(a).toBe(b)
})
})
})
3 changes: 2 additions & 1 deletion src/core/fingerprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ export function fingerprint(
return md5(dedupKey)
}

const normalizedTitle = normalizeMessage(title, config.normalizers)
const normalizedMessage = normalizeMessage(message, config.normalizers)
const stackKey = extractStackKey(error, config.stackDepth)
const errorName = error?.name ?? title
const errorName = error?.name ?? normalizedTitle
Comment on lines +72 to +75
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The normalizedTitle is computed eagerly using multiple regex replacements even when an error object is provided. Since error.name takes precedence in the errorName assignment, this computation is redundant when an error is present. It is more efficient to compute it only when needed.

Suggested change
const normalizedTitle = normalizeMessage(title, config.normalizers)
const normalizedMessage = normalizeMessage(message, config.normalizers)
const stackKey = extractStackKey(error, config.stackDepth)
const errorName = error?.name ?? title
const errorName = error?.name ?? normalizedTitle
const normalizedMessage = normalizeMessage(message, config.normalizers)
const stackKey = extractStackKey(error, config.stackDepth)
const errorName = error?.name ?? normalizeMessage(title, config.normalizers)


return md5(errorName + normalizedMessage + stackKey)
}
2 changes: 1 addition & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const DEFAULT_QUEUE: QueueConfig = {
}

export const DEFAULT_FINGERPRINT: FingerprintConfig = {
stackDepth: 3,
stackDepth: 1,
normalizers: [],
}

Expand Down
Loading