Skip to content

Conversation

@morgan-wowk
Copy link

@morgan-wowk morgan-wowk commented Jan 26, 2026

Description

Added Bugsnag error management service with custom error normalization and grouping capabilities. The implementation includes:

  • A configurable Bugsnag initialization module
  • Environment variable support for API keys and endpoints
  • Custom error message normalization for better error grouping
  • Metadata enrichment with extracted values and context information
  • Support for custom grouping keys

Type of Change

  • New feature
  • Improvement

Checklist

  • I have tested this does not break current pipelines / runs functionality
  • I have tested the changes on staging

Test Instructions

  1. Set the required environment variables in your .env file:
  2. Trigger an error in the application to verify it's properly captured and normalized in the Bugsnag dashboard

Additional Comments

The error normalization helps group similar errors together even when they contain different dynamic values, improving our error tracking and debugging capabilities.

Copy link
Author

morgan-wowk commented Jan 26, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@morgan-wowk morgan-wowk force-pushed the 01-26-feat_add_bugsnag_error_reporting_service_initialize_bugsnag_sdk_with_custom_error_normalization_and_grouping._reads_configuration_from_environment_variables_and_applies_normalization_to_all_reported_errors branch 3 times, most recently from 9688389 to c3cfc88 Compare January 26, 2026 21:10
@morgan-wowk morgan-wowk marked this pull request as ready for review January 26, 2026 21:12
@morgan-wowk morgan-wowk requested a review from a team as a code owner January 26, 2026 21:12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we typically don't do barrel files and we just directly import from the files where we need. I'd recommend using @.cursorrules to catch these sort of "style" errors.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. Done. Thanks

};

// Initialize Bugsnag on module load
initializeBugsnag();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets export this function and Initialize where we are using it (maybe src/index.tsx)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Good suggestion

return;
}

Bugsnag.start({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets wrap this in a try catch:

try {
  Bugsnag.start({ ... });
} catch (error) {
  console.error("Failed to initialize Bugsnag:", error);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

onError: (event) => {
// Only normalize and enhance generic "Error" instances
// Custom error classes (NetworkError, ValidationError, etc.) are preserved as-is
if (event.errors[0].errorClass === "Error") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets abstract this into constants:

const GENERIC_ERROR_CLASS = "Error";

if (event.errors[0].errorClass === GENERIC_ERROR_CLASS) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 52 to 83
onError: (event) => {
// Only normalize and enhance generic "Error" instances
// Custom error classes (NetworkError, ValidationError, etc.) are preserved as-is
if (event.errors[0].errorClass === "Error") {
const errorMessage = event.errors[0].errorMessage;
const { normalizedMessage, extractedValues } =
normalizeErrorMessage(errorMessage);

// Set custom grouping hash for better error grouping
event.groupingHash = normalizedMessage;

// Update errorClass to show the normalized message in Observe UI
event.errors[0].errorClass = normalizedMessage;

// Add custom grouping key to metadata if configured
if (config.customGroupingKey) {
event.addMetadata("custom", {
[config.customGroupingKey]: normalizedMessage,
});
}

// Add extracted values as metadata for debugging
if (Object.keys(extractedValues).length > 0) {
event.addMetadata("extracted_values", extractedValues);
}
}

// Add pathname for context (for all errors)
event.addMetadata("context", { pathname: window.location.pathname });
},
});
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fairly complex. Can we abstract it into a function?

const handleGenericError = (event: Bugsnag.Event, config: BugsnagConfig) => { ... };

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure. Added some unit tests too.

@morgan-wowk morgan-wowk changed the base branch from 01-26-feat_add_error_message_normalization_utility_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 to graphite-base/1695 January 28, 2026 18:33
@morgan-wowk morgan-wowk force-pushed the 01-26-feat_add_bugsnag_error_reporting_service_initialize_bugsnag_sdk_with_custom_error_normalization_and_grouping._reads_configuration_from_environment_variables_and_applies_normalization_to_all_reported_errors branch from c3cfc88 to 6cf38f9 Compare January 28, 2026 18:33
@morgan-wowk morgan-wowk changed the base branch from graphite-base/1695 to 01-26-feat_add_error_message_normalization_utility_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 January 28, 2026 18:33
@morgan-wowk morgan-wowk changed the base branch from 01-26-feat_add_error_message_normalization_utility_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 to graphite-base/1695 January 28, 2026 18:47
@morgan-wowk morgan-wowk force-pushed the 01-26-feat_add_bugsnag_error_reporting_service_initialize_bugsnag_sdk_with_custom_error_normalization_and_grouping._reads_configuration_from_environment_variables_and_applies_normalization_to_all_reported_errors branch from 6cf38f9 to ad2ef91 Compare January 28, 2026 18:48
@morgan-wowk morgan-wowk changed the base branch from graphite-base/1695 to 01-26-feat_add_error_message_normalization_utility_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 January 28, 2026 18:48
@morgan-wowk morgan-wowk force-pushed the 01-26-feat_add_bugsnag_error_reporting_service_initialize_bugsnag_sdk_with_custom_error_normalization_and_grouping._reads_configuration_from_environment_variables_and_applies_normalization_to_all_reported_errors branch from ad2ef91 to 62bc345 Compare January 28, 2026 19:20
@morgan-wowk morgan-wowk force-pushed the 01-26-feat_add_error_message_normalization_utility_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 branch from 1119b6f to 7ab4019 Compare January 28, 2026 21:27
@morgan-wowk morgan-wowk force-pushed the 01-26-feat_add_bugsnag_error_reporting_service_initialize_bugsnag_sdk_with_custom_error_normalization_and_grouping._reads_configuration_from_environment_variables_and_applies_normalization_to_all_reported_errors branch 2 times, most recently from 58af5dc to 0217c23 Compare January 28, 2026 21:48
Initialize Bugsnag SDK with custom error normalization and grouping. Reads configuration from environment variables and applies normalization to all reported errors.
@morgan-wowk morgan-wowk force-pushed the 01-26-feat_add_bugsnag_error_reporting_service_initialize_bugsnag_sdk_with_custom_error_normalization_and_grouping._reads_configuration_from_environment_variables_and_applies_normalization_to_all_reported_errors branch from 0217c23 to e60eb29 Compare January 28, 2026 21:58
@morgan-wowk morgan-wowk force-pushed the 01-26-feat_add_error_message_normalization_utility_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 branch from 7ab4019 to d7fc62b Compare January 28, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants