Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ActiveSupport::ErrorReporter #1153

Closed
olegantonyan opened this issue Mar 20, 2024 · 3 comments
Closed

Using ActiveSupport::ErrorReporter #1153

olegantonyan opened this issue Mar 20, 2024 · 3 comments
Assignees

Comments

@olegantonyan
Copy link

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
Copy link
Author

olegantonyan commented Mar 21, 2024

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

@tmimura39
Copy link

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.
getsentry/sentry-ruby#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.

@waltjones
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants