Tuần trước release version 4.0.0 honeybadger Ruby gem. Release bao gồm long-awaited feature làm easier customize error reports trước khi sent to Honeybadger. Cũng did much-needed refactoring, và few removals/deprecations. Đừng lo — most API unchanged, upgrading relatively painless cho most users.
Introducing before_notify Callback
Prior versions honeybadger gem provided three callbacks customize various aspects reported errors:
Honeybadger.backtrace_filter— callback modify backtrace reported to HoneybadgerHoneybadger.exception_fingerprint— callback customize error grouping in HoneybadgerHoneybadger.exception_filter— callback determine if error report should skip entirely
Beyond callbacks, no global way change other data error reports: error message, tags, request data — beyond rescuing reporting exceptions locally. That's where new before_notify callback comes in. New callback versatile completely replacing all three previous callbacks, now deprecated.
Moving forward, dùng before_notify callback accomplish all tasks, và more. Multiple callbacks supported, greater flexibility configuring Honeybadger:
Honeybadger.configure do |config|
# Ignore error report
# Replaces Honeybadger.exception_filter
config.before_notify do |notice|
notice.halt! if notice.controller == 'auth'
end
# Modify 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
Excited về new before_notify callback, believe open up new options moving forward!
Upgrading To 4.x
Most users on 3.x, upgrading uneventful. Nếu using three callbacks mentioned, cần update dùng before_notify thay thế, và potentially few minor changes, public API Notice (object passed to callback) changed slightly.
More Information:
- 3.x to 4.x Upgrade Guide
- Complete CHANGELOG