How to Implement Reliable Error Reporting Pipelines
Capture, deduplicate and route exceptions reliably without flooding a tracker, leaking secrets or losing the errors that matter.
On this page
Introduction
Error reporting looks trivial until scale and trust arrive. Left unbounded, every exception in a retry loop becomes thousands of identical events that bury the real signal. Captured naively, exception payloads leak access tokens, passwords and personal data into a third-party tracker. Handled unreliably, the reporter itself throws, or the network to the tracker is down and the error disappears. A reliable pipeline deduplicates, scrubs, samples, and buffers, so that the errors that matter arrive intact while the noise stays out.
Capture with Boundaries, Not Global Catches
A single process-level handler is a last resort, not the primary mechanism. Capture errors where you have context: the request handler, the job runner, the message consumer, so the report carries the operation, the inputs and the trace id. The process-level handler is what catches the ones that escaped, and it should mark the process unhealthy rather than silently continuing.
Attach a correlation id to every report so an error can be joined to its logs and trace. Without it, an error report is an isolated stack trace; with it, it links to the whole request. The same trace id in metrics, logs and errors is what makes an incident diagnosable from one screen.
import { trace } from '@opentelemetry/api';
export async function handleRequest(req: Request, fn: () => Promise<Response>) {
try {
return await fn();
} catch (err) {
const span = trace.getActiveSpan();
reportError(err, {
traceId: span?.spanContext().traceId, // joins error to trace
route: req.url,
method: req.method,
});
return new Response('Internal Server Error', { status: 500 });
}
}
Deduplication and Fingerprinting
A retry loop can emit millions of copies of one exception. Grouping them by a fingerprint turns millions of events into one issue with a count, which is what a human can triage. A fingerprint is typically derived from the exception type, the top stack frames and a normalised message, with variable parts such as ids and timestamps stripped out.
Fingerprint stability matters more than precision. If the fingerprint changes when an id changes, grouping fails; if it collapses unrelated errors together, triage misleads. Strip volatile tokens before hashing, keep the exception class and the first few frames, and test the fingerprint against real reports.
import { createHash } from 'node:crypto';
function normaliseMessage(msg) {
return msg
.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, '<uuid>')
.replace(/\b\d+\b/g, '<n>')
.replace(/"(?:[^"\\]|\\.)*"/g, '<str>');
}
function fingerprint({ name, message, frames }) {
const parts = [name, normaliseMessage(message), ...frames.slice(0, 3)].join('|');
return createHash('sha256').update(parts).digest('hex').slice(0, 16);
}
Scrubbing Sensitive Data
Exception payloads are full of secrets: request headers carry authorization tokens, database errors embed connection strings, form data contains passwords. Every report must pass through a scrubber that removes known-sensitive keys and patterns before it leaves the process. This is the same discipline as log redaction, applied to error reports.
Scrub by allow-list where possible. Rather than trying to remove everything sensitive, decide which fields are safe to send and drop the rest. Deny-listing fails because new fields appear over time and the one you forgot is the one with the credential in it. Keep the scrubber versioned so a change is auditable.
const SENSITIVE_KEYS = /^(authorization|cookie|set-cookie|password|secret|token|api[-_]?key)$/i;
function scrub(value, depth = 0) {
if (depth > 6) return '[deep]';
if (Array.isArray(value)) return value.map((v) => scrub(v, depth + 1));
if (value && typeof value === 'object') {
return Object.fromEntries(
Object.entries(value).map(([k, v]) =>
SENSITIVE_KEYS.test(k) ? [k, '[redacted]'] : [k, scrub(v, depth + 1)],
),
);
}
if (typeof value === 'string') {
return value.replace(/Bearer\s+[\w.\-]+/g, 'Bearer [redacted]');
}
return value;
}
Reliable Delivery and Buffering
The reporter must never break the application and must survive a tracker outage. Send asynchronously, off the request path, and buffer reports in a bounded queue; if the queue is full, drop the oldest rather than grow memory without limit. Retry with backoff, but cap the retries so a persistent outage does not consume the queue with retries of stale errors.
Deduplicate at send time too. If the same fingerprint arrives thousands of times per second, collapse them into a single report with a count and send that, rather than shipping each occurrence. This protects the tracker, your bill and the recipient’s attention all at once.
# Error delivery path
capture -> fingerprint -> scrub -> coalesce (count per fingerprint/window)
-> bounded async queue -> batched send with retry+backoff
-> on failure: drop oldest, keep newest, never block the request
Sampling and Rate Limiting
Even coalesced, a busy service can overwhelm a tracker. Rate-limit per fingerprint and per service so at most N reports per minute get through, and always admit the first occurrence so a new error is never missed. Sample repetitive benign errors heavily while keeping every new fingerprint at full fidelity.
Preserve the counts you drop. If you send one report out of a thousand but record that a thousand happened, the issue shows the true frequency without shipping the payloads. The count is what distinguishes a rare error from a storm, and losing it makes the sampling misleading.
Routing and Ownership
Route reports to the team that owns the code, using a service-to-owner mapping that lives with the service definition. An error routed to a team that cannot fix it becomes a misdirected page. For errors that indicate user-facing breakage, escalate to the same channel as a burn-rate alert; for background noise, open a ticket.
Close the loop with regression status. When a fingerprint stops appearing after a deploy, mark it resolved; when it reappears, reopen it. This lets the team see what is fixed and what is regressing, and it prevents the tracker from accumulating thousands of stale issues nobody trusts.
Common Pitfalls and Conclusion
Do not report on the request path synchronously. Do not send unsanitised payloads. Do not fingerprint on volatile values or grouping fails. Do not drop without preserving counts. Do not let the process-level handler continue silently after an unrecoverable error. And do not treat the tracker as the source of truth for availability; it is for diagnosis, while metrics are for alerting.
A reliable error pipeline captures with context, fingerprints to group, scrubs to protect, buffers to survive outages, samples to protect the tracker, and routes to owners. Built this way it delivers the errors that matter, intact and actionable, while keeping the floods and the secrets out.
Sources: Sentry: Grouping and fingerprints, OWASP: Logging cheat sheet, Google SRE: Addressing cascading failures.
FAQ
- Should error reporting run on the request path?
- No. Send asynchronously off the request path with a bounded buffer so the reporter never adds latency or fails the request. If the tracker is down, buffer and retry, and drop the oldest when the buffer fills.
- How do I stop one retry loop from flooding the tracker?
- Fingerprint and coalesce: group identical errors and send one report with a count per window, rate-limit per fingerprint, and always admit the first occurrence so a new error is never missed.
Report a problem with this articleOpens a pre-filled issue on GitHub.