Last week we released version 4.0.0 of the honeybadger Ruby gem. This release includes a long-awaited feature which makes it even easier to customize your error reports before they are sent to Honeybadger. We also did some much-needed refactoring, and made a few removals and deprecations for good measure. Don't worry, though—most of the API remains unchanged, so upgrading should be a relatively painless process for most users.

Introducing the before_notify callback

Prior versions of the honeybadger gem provided three callbacks which could be used to to customize various aspects of reported errors:

  1. Honeybadger.backtrace_filter — a callback to modify the backtrace that is reported to Honeybadger
  2. Honeybadger.exception_fingerprint — a callback to customize the grouping of errors in Honeybadger
  3. Honeybadger.exception_filter — a callback to determine if the error report should be skipped entirely

Beyond these callbacks, there was no global way to change other data in error reports, such as the error message, tags, or request data—beyond rescuing and reporting exceptions locally. That's where the new before_notify callback comes in. In fact, the new callback is so versatile that it's completely replacing all three of the previous callbacks, which are now deprecated.

Moving forward, you can use a before_notify callback to accomplish all of these tasks, and more. Multiple callbacks are also supported, which provides greater flexibility when configuring Honeybadger:

Honeybadger.configure do |config|

  # Ignore an error report
  # Replaces Honeybadger.exception_filter
  config.before_notify do |notice|
    notice.halt! if notice.controller == 'auth'
  end

  # Modify the backtrace
  # Replaces Honeybadger.backtrace_filter
  config.before_notify do |notice|
    notice.backtrace.reject!{|l| l =~ /gem/ }
  end

  # Customize error grouping
  # Replaces Honeybadger.exception_fingerprint
  config.before_notify do |notice|
    notice.fingerprint = 'new fingerprint'
  end

  # Change all the properties!
  config.before_notify do |notice|
    notice.api_key = 'custom api key'
    notice.error_message = "badgers!"
    notice.error_class = 'MyError'
    notice.backtrace = ["/path/to/file.rb:5 in `method'"]
    notice.fingerprint = 'some unique string'
    notice.tags = ['foo', 'bar']
    notice.context = { user: 33 }
    notice.controller = 'MyController'
    notice.action = 'index'
    notice.parameters = { q: 'badgers?' }
    notice.session = { uid: 42 }
    notice.url = "/badgers"
  end

end

We're excited about the new before_notify callback, and believe it will open up a lot of new options moving forward!

Upgrading to 4.x

For most users on 3.x, upgrading should be uneventful. If you're using the three callbacks which I mentioned above, then you'll need to update them to use before_notify instead, and potentially make a few other minor changes, as part of the public API for Notice (the object passed in to the callback) has changed slightly.

For more information:

Get the Honeybadger newsletter

Each month we share news, best practices, and stories from the DevOps & monitoring community—exclusively for developers like you.
    author photo
    Joshua Wood

    Josh started hacking on IRC scripts in the late nineties and has been hacking on computers (and businesses) ever since. As a co-founder of Honeybadger he works on the product, leads marketing and developer relations, and is involved in many open-source projects.

    More articles by Joshua Wood
    An advertisement for Honeybadger that reads 'Turn your logs into events.'

    "Splunk-like querying without having to sell my kidneys? nice"

    That’s a direct quote from someone who just saw Honeybadger Insights. It’s a bit like Papertrail or DataDog—but with just the good parts and a reasonable price tag.

    Best of all, Insights logging is available on our free tier as part of a comprehensive monitoring suite including error tracking, uptime monitoring, status pages, and more.

    Start logging for FREE
    Simple 5-minute setup — No credit card required