Customizing error reports
Honeybadger has several ways to customize the data reported with each error to add custom metadata, request information, and more.
Adding context
Section titled “Adding context”Honeybadger can display additional custom key/value metadata — or “context” — with each error report. Context data can be anything, but a few keys have a special meaning in Honeybadger.
Use Honeybadger.setContext to add context to error reports. You can call
setContext as many times as you like, and it will be reset on each page load.
New context data is merged with existing data:
// On loadHoneybadger.setContext({ user_id: 123,});
// LaterHoneybadger.setContext({ backbone_view: "tracks",});
// The context now contains { user_id: 123, backbone_view: 'tracks' }If you’ve used Honeybadger.setContext to store context data, you can clear it
with Honeybadger.clear():
// Set the context to {}Honeybadger.clear();While you can add any key/value data to context, a few keys have special meaning in Honeybadger:
| Option | Description |
|---|---|
user_id | The String user ID used by Honeybadger to aggregate user data across occurrences on the error page. |
user_email | Same as user_id, but for email addresses |
tags | A String comma-separated list of tags. When present, tags will be applied to errors with this context. |
Capturing breadcrumbs
Section titled “Capturing breadcrumbs”Breadcrumbs are events that happen right before an error occurs. Honeybadger captures many types of breadcrumbs automatically, such as click events, console logs, and Ajax requests. To learn more about breadcrumbs, check out Capturing Events with Breadcrumbs.
To use Breadcrumbs, you must first enable them in your honeybadger.js config:
Honeybadger.configure({ // ... breadcrumbsEnabled: true,});To capture a breadcrumb anywhere in your application:
Honeybadger.addBreadcrumb("Sent Email", { category: "custom", metadata: { user_id: user.id, body: body },});See the guide for additional options and a list of breadcrumbs that are automatically captured.
Modifying data
Section titled “Modifying data”If you need full control over the data that is reported, you can inspect and
modify all the data on the notice using a Honeybadger.beforeNotify handler:
Honeybadger.beforeNotify(function (notice) { notice.params = myParams;});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
Sending cookies
Section titled “Sending cookies”To automatically send cookies with all error reports, use the following
beforeNotify handler:
Honeybadger.beforeNotify(function (notice) { notice.cookies = document.cookie;});