Customizing error grouping
Honeybadger groups similar exceptions together using rules which we’ve found to work the best in most cases. The default information we use to group errors is:
- The file name, method name, and line number of the error’s location
- The class name of the error
- The component/controller name
We use this information to construct a “fingerprint” of the exception. Exceptions with the same fingerprint are treated as the same error in Honeybadger.
You can customize the grouping for each exception by changing the error class name, component, or stack trace—or by sending a custom fingerprint.
Grouping by component
Section titled “Grouping by component”If you have components that you’d prefer to monitor separately, a quick way to get custom error grouping is to specify a component which errors on the current page belong to:
Honeybadger.configure({ // ... component: "users", action: "index",});The action is optional, and does not affect grouping. In Rails, for instance,
the component and action could map to the controller and action names,
respectively.
You can also specify the component (and action) when reporting caught
errors:
Honeybadger.notify(error, { component: "myComponent",});Creating your own fingerprints
Section titled “Creating your own fingerprints”You can also create your own fingerprints by assigning a unique string to the
fingerprint option. Errors which have the same fingerprint will be grouped,
while Honeybadger’s default fingerprint will be ignored.
To calculate a fingerprint when reporting caught errors:
Honeybadger.notify(err, { fingerprint: "my unique fingerprint",});To calculate a fingerprint for all errors (even uncaught ones), use a
beforeNotify handler:
Honeybadger.beforeNotify(function (notice) { notice.fingerprint = calculateFingerprint(notice);});In this example, the function calculateFingerprint should use the properties
on notice to generate a string that is unique for each type of error.
The following notice properties are available in notice objects:
notice.stack- The stack trace (read only)notice.backtrace- The parsed backtrace objectnotice.name- The exception class namenotice.message- The error messagenotice.url- The current urlnotice.projectRoot- The root urlnotice.environment- Name of the environment. example: “production”notice.component- Similar to a rails controller name. example: “users”notice.action- Similar to a rails action name. example: “create”notice.fingerprint- A unique fingerprint, used to customize grouping of errors in Honeybadgernotice.context- The context objectnotice.tags- A string comma-separated list of tagsnotice.params- An object of request parametersnotice.session- An object of request session key/valuesnotice.headers- An object of request headersnotice.cookies- An object of cookie key/values. May also be sent as a string in the document.cookie “foo=bar;bar=baz” format.
The following additional notice properties are available in afterNotify
handlers:
notice.id- The UUID of the error in Honeybadger