Skip to content
Book a call

Production errors as issues, and what counts as the same error

· 4-minute read · Engineering · by Direct Softworks

A small watcher reads the container log and files an issue per error. Filing is the easy part. Deciding when two messages are the same error is the whole job.

There is no hosted error tracker on our site. Production errors become issues in our own repository, titled with an [auto] prefix, filed by a small watcher that runs on the server: one Python program, no dependencies, following the application container's log.

It is a short program, and most of it is plumbing. The part worth writing about is a single function, the one that decides whether a new error is something we have already seen. It got that wrong once, in a way that produced eighteen issues for one condition that was not even a failure.

The shape of it

The watcher follows the container's log stream, the same output docker logs -f shows. A stack trace arrives as many lines, so lines that arrive together are grouped into one event rather than read one at a time. Each event gets a fingerprint. A new fingerprint opens a new issue. A fingerprint that already has an issue adds a comment to it instead, so a recurring error becomes one issue with a history rather than a page of duplicates.

That is the whole design. Everything interesting happens in the fingerprint, because the fingerprint is the definition of "the same error", and nobody writes that definition down until it is wrong.

It reads text, not severity

The first surprise had nothing to do with fingerprints. A container log is text. It carries no severity field, and in Node, console.warn is documented as an alias for console.error: both write to standard error. So when a framework logs a warning by passing an Error object to console.warn, the log line begins with Error: exactly as a real failure would.

A watcher that matches text therefore files warnings as errors. The log stream had thrown away the one fact the watcher needed, which was whether anything had actually gone wrong. Next.js logs a few conditions this way on purpose: situations it has noticed, recovered from, and wants you to know about.

Normalising, and the hex that slipped through

Two occurrences of the same error rarely produce identical text. One mentions order 4411 and the next order 4412. One carries a request id, the next a different one. So before hashing, a normalising step replaces the variable parts with placeholders, and only the result is fingerprinted.

Ours folded three things: UUIDs, hexadecimal literals written with a 0x prefix, and long numbers. It did not fold long hexadecimal words without the prefix. That gap stayed invisible until a message carried a per-build hash.

After a deploy, a browser still holding a page from the previous build can call a server action by an id the new build no longer knows. Next.js logs a warning about it and recovers. The id in that warning is a long run of hex characters, different for every build and often for every action. So the watcher filed it, because the text said Error, and filed it as new, because the hash made every occurrence unique. Eighteen issues, one cause, and nothing broken.

The fix was two changes. Runs of twelve or more hex characters now fold to a single placeholder, so per-build hashes stop creating new fingerprints. And an ignore list skips the specific conditions the framework recovers from by itself.

The ignore list is where bugs go to hide

An ignore list is necessary and dangerous in equal measure. Every entry is a sentence that says "this text is never worth a human's attention", and that sentence has to stay true through every future version of the framework that produces it.

So keep entries narrow. Match the specific message, not a word in it. And for each entry, be able to say what recovers from the condition and how you know. If you cannot name the recovery, you are not ignoring noise, you are hiding a failure that has simply not hurt anyone yet.

Testing a watcher without waiting for an error

The watcher has a parse-test mode: feed it log text on standard input and it prints what it would have filed, without filing anything. Calling the fingerprint function directly on two messages is the fastest proof that a normalising change does what you meant before you restart the service. A rule that decides what counts as the same thing deserves a test as much as any business rule does, and it rarely gets one.

There is one honest debt. The watcher lives only on the server, not in the repository. A change to it is made on the box and exists only there, and rebuilding the machine would lose it. It is small enough that this has not hurt yet, and that is exactly the reasoning that lets small tools rot.

The wider point

Deduplication looks like a convenience feature. It is really a definition, and a definition you never wrote down is still a definition, just one you cannot review. Before you trust any system that groups events, whether error trackers, alerting rules or support queues, find out what it considers the same, and test it against the messages that vary in ways you did not expect.

And remember what the log can and cannot tell you. As with the reverse proxy that logged nothing, the stream you are reading was shaped by decisions made somewhere else, and the absence of a field is not evidence of anything.

More notes