rollbar-gem icon indicating copy to clipboard operation
rollbar-gem copied to clipboard

Using ActiveSupport::ErrorReporter

Open olegantonyan opened this issue 1 year ago • 1 comments

I'm trying to make Rollbar work with Rails' new error handling mechanism https://guides.rubyonrails.org/error_reporting.html

::Rollbar.configure do |config|
  config.access_token = '...'
  config.environment = ::Rails.env.to_s

  config.disable_monkey_patch = true
  config.disable_rack_monkey_patch = true
  config.disable_action_mailer_monkey_patch = true
end

class ErrorSubscriber
  def report(error, handled:, severity:, context:, source: nil)
    ::Rollbar.log(severity.to_s, error, context: context, source: source)
  end
end

::Rails.error.subscribe(ErrorSubscriber.new)

But the problem is Rollbar monkey patches everything to intercept errors, so it ends up in duplicate error reports: one from Rails ErrorSubscriber, and another from within Rollbar gem.

My first attempt to solve this was trying to disable all monkey patches. But no luck disable_monkey_patch config option does not disable Rails (lib/rollbar/plugins/rails.rb). Adding dependency { !configuration.disable_monkey_patch } there doesn't work. Only completly commenting out all monkey patch code works.

Eventally what I'd like to rely on Rails' ErrorSubscriber alone, and use only Rollbar's server-side to receive messages. No monkey patches, no error interceptions - nothing. Maybe even use raw api directly without the gem (https://docs.rollbar.com/reference/create-item)

This may sound kind of stupid, but the goal is to test how this new ErrorSubscriber works. Because "traditional" approach with monkey-patches works only until you have multiple gems monkey-patching the same thing has already shot me in the foot, so the addition of Rails native error handling mechanism seems like a good idea.

olegantonyan avatar Mar 20 '24 06:03 olegantonyan

I ended up using raw api instead of the gem: https://github.com/omnipackage/omnipackage-web/blob/master/config/initializers/error_subscriber.rb https://github.com/omnipackage/omnipackage-web/tree/master/lib/rollbar_nano

So far ActiveSupport::ErrorReporter looks good, will see whether it worth it in the long run

olegantonyan avatar Mar 21 '24 07:03 olegantonyan

But the problem is Rollbar monkey patches everything to intercept errors, so it ends up in duplicate error reports: one from Rails ErrorSubscriber, and another from within Rollbar gem.

This issue is important to me as well.

The sentry gem has taken the following actions. https://github.com/getsentry/sentry-ruby/pull/1738

If the Rollbar Gem does not support this, we have no choice but to “not use ActiveSupport::ErrorReporter” or “create our own thin Rollbar Middrware”.

It would be helpful if you could give us Rollbar official thoughts.

tmimura39 avatar Aug 16 '24 07:08 tmimura39

Thanks everyone. Support for this is published in v3.6.0. https://github.com/rollbar/rollbar-gem/releases/tag/v3.6.0

Docs will be updated. See the PR for config.

waltjones avatar Aug 30 '24 12:08 waltjones