r/rails • u/GetForgeOps • Oct 22 '26
Grouping errors without sending the message: hashing normalized exception messages in Rails
Problem I hit: for apps with health or personal data, the exception message is the riskiest part of an error report, because we put the failing value in it. But error trackers group occurrences by message, so you can't just drop it.
What I ended up doing: normalize the message in-process (hex addresses, UUIDs and digit runs replaced), SHA-256 it, keep the first 32 hex chars, and send that instead of the text. "Couldn't find Patient with id=12" and "id=13" group together; different messages stay apart; nothing about the text goes over the wire.
The normalization is a few lines of Ruby:
normalized = message
.gsub(/0x\h{4,}/, "0x")
.gsub(/\b\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\b/, "<uuid>")
.gsub(/\b\d+\b/, "<n>")
Digest::SHA256.hexdigest(normalized)[0, 32]
Raw request paths get similar treatment: a route template like /patients/:id is kept, but an unmatched raw path keeps only its first segment, since anything after it could be a name.
Disclosure: I built this into my error tracking gem (forge_ops_tracker, MIT, source at https://github.com/Luke-Popwell/forge-ops-tracker-ruby) as a strict privacy mode. Longer write-up with the tradeoffs: https://getforgeops.net/guides/error-reports-without-personal-data
Curious whether anyone handles this differently, e.g. structured error codes instead of messages, or filtering in an exception notifier before it leaves.
2
u/Codalio-SoftwareFact Oct 22 '26
Nice approach. One thing I’d watch for: anything that isn’t a digit run or UUID still goes into the hash as is. So “Couldn’t find user with email=jane@example.com” gets a different hash per user, which breaks the grouping, and since emails and names are pretty guessable, someone with a list of candidates could match the hash back to the value. Might be worth also normalizing quoted strings and anything email-shaped.
The other way I’ve seen people handle it is grouping by exception class plus the top in-app backtrace frame instead of the message. Same bug usually throws from the same line, so you don’t need the message for grouping at all.
1
u/sshaw_ Oct 22 '26
Sensitive information, be it PII or system info that an attacker can use, in exceptions is overlooked quite a bit.
I've had to do general exception grouping in Airbrake, Rollbar, etc... but that's usually specific to the Rails application and service.
I think the better route is to use custom exceptions, where appropriate, and put the sensitive data elsewhere in the exception class and ensure it's not output via
#to_s,#message, etc...Though I think
"Couldn't find Patient with id=12"is fine as is