Customizing Error Reports

Honeybadger has several ways to customize the data reported with each error to add custom metadata, request information, and more.

Custom Metadata (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.resetContext:

// Set the context to {}
Honeybadger.resetContext();

// Clear the context, then set it to `{ user_id: 123 }`
Honeybadger.resetContext({
  user_id: 123
});

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.

Changing Notice Properties

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 beforeNotify handlers:

  • stack - The stack trace
  • name - The exception class name
  • message - The error message
  • url - The current url
  • projectRoot - The root url
  • environment - Name of the environment. example: "production"
  • component - Similar to a rails controller name. example: "users"
  • action - Similar to a rails action name. example: "create"
  • fingerprint - A unique fingerprint, used to customize grouping of errors in Honeybadger.
  • context - The context object.
  • params - An object of request parameters.
  • cookies - An object of cookie key/values. May also be sent as a string in the document.cookie "foo=bar;bar=baz" format.

Sending Request Information

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

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