Computer >> Computer tutorials >  >> Programming >> ruby

The honeybadger gem 4.0 has been released!

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:

  • 3.x to 4.x Upgrade Guide
  • Complete CHANGELOG