feat: add error message normalization and integration#1718
feat: add error message normalization and integration#1718morgan-wowk merged 1 commit intomasterfrom
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
43d2c0a to
a0597d8
Compare
b29beaf to
7dd0dc9
Compare
f7acc67 to
0dcd36d
Compare
a0597d8 to
5bdaabd
Compare
0dcd36d to
c7d466b
Compare
4e541c5 to
88883ad
Compare
54c9881 to
b717d56
Compare
Mbeaulne
left a comment
There was a problem hiding this comment.
left a few non blocking comments
| if (event.errors[0].errorClass === GENERIC_ERROR_CLASS) { | ||
| const errorMessage = event.errors[0].errorMessage; | ||
| const { normalizedMessage, extractedValues } = | ||
| normalizeErrorMessage(errorMessage); | ||
|
|
||
| event.groupingHash = normalizedMessage; | ||
| event.errors[0].errorClass = normalizedMessage; | ||
|
|
||
| if (BUGSNAG_CUSTOM_GROUPING_KEY) { | ||
| event.addMetadata("custom", { | ||
| [BUGSNAG_CUSTOM_GROUPING_KEY]: normalizedMessage, | ||
| }); | ||
| } | ||
|
|
||
| if (Object.keys(extractedValues).length > 0) { | ||
| event.addMetadata("extracted_values", extractedValues); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I remember doing something similar in other codebases with event.errors[0] but I have lost all context. What happens of there are multiple errors? do we need to account for them?
There was a problem hiding this comment.
After some research, I learned that Bugsang supports multiple erorrs on an event but this is not really seen in Javascript / frontend apps. It would be seen for example in some backend applications that are explicitly tracking and reporting multiple errors to Bugsnag. I remember implementing this once in the past for an API endpoint that would perform multiple independent tasks and report errors from each in a single response.
|
|
||
| type NormalizationReplacer = ( | ||
| match: string, | ||
| ...args: any[] |
There was a problem hiding this comment.
Should this be unknown[] instead of any?
| name: "uuid", | ||
| // Matches UUIDs in paths (e.g., /api/executions/019b3428-a0f0-d259-b764-ae0efbf37a64/status) | ||
| pattern: | ||
| /\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(\/|$|\)|\s)/gi, |
There was a problem hiding this comment.
can we abstract this pattern out to a named variable? Looking at this regex I don't reallly know what it does. I get that there is a comment, but I wonder if we just remove the comment in place of a named variable.
const MATCH_UUID_IN_PATH = regex
Thoughts?
There was a problem hiding this comment.
I switched to constants with as clear names as I could get. Seems reasonable!
| { | ||
| name: "numericPathId", | ||
| // Matches numeric IDs in paths (e.g., /users/12345/profile) | ||
| pattern: /\/(\d+)(\/|$|\)|\s)/g, |
| name: "alphanumericPathId", | ||
| // Matches alphanumeric IDs in paths that are 6+ chars with both letters and digits (e.g., /files/abc123defghi/data) | ||
| pattern: | ||
| /\/([a-zA-Z0-9]*\d[a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]{6,}|[a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*\d[a-zA-Z0-9]{6,})(\/|$|\)|\s)/g, |
| { | ||
| name: "queryParamId", | ||
| // Matches query parameter values that contain digits or are hexadecimal (e.g., ?id=abc123 or ?token=a1b2c3) | ||
| pattern: /([?&][a-zA-Z_]+)=([0-9a-zA-Z-]{6,})/g, |
| name: "hashOrDigest", | ||
| // Matches common hash lengths: MD5 (32), SHA-1 (40), SHA-256 (64) | ||
| // More specific than 16+ to avoid false positives with sequential numbers | ||
| pattern: /\b([a-f0-9]{32}|[a-f0-9]{40}|[a-f0-9]{64})\b/gi, |
b717d56 to
e31158e
Compare
88883ad to
e5ea46c
Compare
e31158e to
7560f78
Compare
7560f78 to
2671a92
Compare
Add utility to normalize error messages by extracting dynamic values (UUIDs, IDs, hashes, etc.) and replacing them with placeholders. This enables better error grouping in monitoring tools like Bugsnag. Integrate normalization into Bugsnag error handler with custom grouping hash.
2671a92 to
95adc7b
Compare
Merge activity
|

Description
Implemented error message normalization for Bugsnag to improve error grouping. This enhancement extracts dynamic values (UUIDs, IDs, hashes) from error messages and replaces them with placeholders, allowing similar errors with different dynamic values to be grouped together.
The implementation includes:
normalizeErrorMessageutility that identifies and extracts common patternsType of Change
Checklist
Test Instructions