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

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 load
Honeybadger.setContext({
  user_id: 123
});

// Later
Honeybadger.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

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

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 object
  • notice.name - The exception class name
  • notice.message - The error message
  • notice.url - The current url
  • notice.projectRoot - The root url
  • notice.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 Honeybadger
  • notice.context - The context object
  • notice.tags - A string comma-separated list of tags
  • notice.params - An object of request parameters
  • notice.session - An object of request session key/values
  • notice.headers - An object of request headers
  • notice.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

To automatically send cookies with all error reports, use the following beforeNotify handler:

Honeybadger.beforeNotify(function(notice){
  notice.cookies = document.cookie;
});