Prompt
How do I dedupe recurring exceptions automatically?
Latest observation
To automatically dedupe recurring exceptions, you generally want to group errors by a stable fingerprint and then aggregate repeated occurrences instead of treating each event as unique.
A practical approach
1. Define a fingerprint for each exception
Create a hash or signature from fields that identify the same issue, such as:
- exception type
- normalized message
- top stack frames
- service/app name
- environment
- endpoint/job name
Example fingerprint inputs:
NullReferenceException | "Object reference not set" | MyService | Prod | OrderController:GetOrder
Then hash that string:
fingerprint = sha256(normalized_signature).hexdigest()
2. Normalize noisy parts
Strip or replace values that change every time but don’t indicate a new problem:
- IDs, timestamps, GUIDs
- file paths with build numbers
- memory addresses
- request-specific values
- line numbers if they fluctuate often
Example normalization:
"User 12345 failed"→"User <id> failed""Order #99881"→"Order #<num>"
3. Store one “open issue” per fingerprint
Instead of creating a new record for every exception, keep a table/collection like:
fingerprintfirst_seenlast_seencountsample_eventstatus(open/resolved)
When a new event arrives:
- if fingerprint exists and issue is open, increment
count, updatelast_seen - otherwise create a new issue
4. Group by time window if needed
If errors are frequent and you want alert deduping, aggregate within windows:
- 1 minute
- 5 minutes
- 1 hour
This helps avoid alert storms while still preserving counts.
5. Use stack-trace similarity
If the top of the stack changes but the root cause is the same, compare only:
- exception type
- top N frames
- deepest application frames
- root cause chain
This is often better than comparing full traces.
Example rule
Treat two exceptions as the same if all are true:
- same exception class
- same normalized message
- same service/environment
- same top 3 non-library stack frames
Example pseudocode
def fingerprint(event):
normalized_message = normalize(event.message)
top_frames = extract_app_frames(event.stacktrace, n=3)
sig = f"{event.type}|{normalized_message}|{event.service}|{event.env}|{top_frames}"
return sha256(sig.encode()).hexdigest()
def ingest(event):
fp = fingerprint(event)
issue = db.find_open_issue(fp)
if issue:
issue.count += 1
issue.last_seen = event.timestamp
db.update(issue)
else:
db.insert({
"fingerprint": fp,
"first_seen": event.timestamp,
"last_seen": event.timestamp,
"count": 1,
"sample_event": event,
"status": "open",
})
If you want to reduce duplicates in alerts specifically
Add alerting rules like:
- send only on first occurrence
- send again after N repeats
- send a digest every X minutes
- suppress duplicates for a cooldown period
Example:
- first event: alert immediately
- events 2–20: increment counter silently
- every 10 minutes: send summary if count increased
Existing tools that already do this
Many error monitoring systems support deduplication/fingerprinting:
- Sentry
- Datadog Error Tracking
- New Relic
- Elastic APM / Observability
- Bugsnag
- Rollbar
They often let you customize fingerprints or grouping rules.
If you want, I can help you design a dedupe strategy for a specific stack, like Python logging, Sentry, ELK, Datadog, or a custom database pipeline.