Airbrake Blog

Introducing code hunks

Written by Kyrylo Silin | Nov 22, 2017 1:14:38 PM

I'm happy to announce that we've added code hunks support to Airbrake. Code hunks are lines of code surrounding each backtrace frame.

Airbrake notifiers collect up to 5 lines of code for each stack frame. Notifiers that support code hunks right now:

  • airbrake-ruby (v2.5.0)
  • gobrake (v3.3.0)
  • phpbrake (v0.5.0)

Every notifier enables code hunks by default. However, there are certain specific rules for Airbrake Ruby. When root_directory is set to some value, then code hunks are collected only for frames inside that directory. It means that the library would be collecting code hunks only for your project skipping dependencies. If root_directory isn't configured, then first ten code hunks are collected. You can disable code hunks with the following code:

Airbrake.configure do |c|
c.code_hunks = false
end

You can also access code hunks via the add_filter API (read notice[:errors].first[:backtrace][:code]). For notifier authors: be sure to check our API documentation to see where code hunks belong in our JSON schema.

Code hunks are available now on all paid plans. However, if you are on the free plan, you still can send them. Once you upgrade to a paid plan, old code hunks that you've sent while being on the free plan would appear in the dashboard.