สัปดาห์ที่แล้วเรา release version 4.0.0 ของ honeybadger Ruby gem Release นี้รวม feature ที่รอนาน ทำให้ customize error reports ก่อนส่งไป Honeybadger ง่ายขึ้น เรายังทำ refactoring ที่จำเป็น และ removals/deprecations เล็กน้อย อย่ากังวล — API ส่วนใหญ่คงเดิม upgrade ควร painless สำหรับ most users
แนะนำ before_notify callback
Prior versions ของ honeybadger gem มี 3 callbacks สำหรับ customize reported errors:
Honeybadger.backtrace_filter— callback แก้ backtrace ที่ report ไป HoneybadgerHoneybadger.exception_fingerprint— callback ปรับ grouping ของ errors ใน HoneybadgerHoneybadger.exception_filter— callback ตัดสินใจว่า skip error report เลย
นอก callbacks นี้ ไม่มี global way เปลี่ยน data อื่นใน error reports เช่น error message, tags, request data — นอกจาก rescue และ report exceptions locally นี่คือที่มาของ before_notify callback ใหม่ จริงๆ callback ใหม่นี้ versatile จน replace ทั้ง 3 callbacks ก่อนหน้า ซึ่งตอนนี้ deprecated
ไปข้างหน้า ใช้ before_notify callback ทำทั้งหมดนี้ และมากกว่า Multiple callbacks รองรับ ให้ flexibility มากขึ้นตอน configure 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
เราตื่นเต้นกับ before_notify callback ใหม่ และเชื่อว่ามันจะเปิด options ใหม่มากมาย!
Upgrade ไป 4.x
สำหรับ most users on 3.x upgrade ควร uneventful ถ้าใช้ 3 callbacks ข้างต้น ต้อง update ให้ใช้ before_notify แทน และอาจ minor changes อื่นๆ เพราะ public API สำหรับ Notice (object ส่งเข้า callback) เปลี่ยนเล็กน้อย
ข้อมูลเพิ่มเติม:
- 3.x to 4.x Upgrade Guide
- Complete CHANGELOG