honeybadger-io / honeybadger-ruby

Ruby gem for reporting errors to honeybadger.io
https://docs.honeybadger.io/lib/ruby/
MIT License
250 stars 146 forks source link

feat: add before_event hook for intercepting events #567

Closed roelbondoc closed 4 months ago

roelbondoc commented 4 months ago

Similar to the before_notify callback, this adds a before_event callback to allow for intercepting of an event. Within the callback you can inspect or modify the payload, or halt! the event if you do not want it to be sent.

Example:

Honeybadger.configure do |config|
  config.before_event do |event|
    if event.event_type == "process_action.action_controller" && event[:controller] == "Rails::HealthController"
      event.halt!
    end
  end
end

Event#event_type - Returns the event_type parameter. Event#ts - Returns the generated timestamp, or the :ts value in the payload if one was present. Event#[] - Allows you to access the event payload data.

Before submitting a pull request, please make sure the following is done:

  1. If you've fixed a bug or added code that should be tested, add tests!
  2. Run rake spec in the repository root.
  3. Use a pull request title that conforms to conventional commits.