Description
Hello!
I'm having troubles getting bugsnag to work in my Rails app together with APM tools (like AppSignal) that still uses alias method chains to hook into rake or other gems or frameworks. https://blog.newrelic.com/engineering/ruby-agent-module-prepend-alias-method-chains/ is a good article that explains the issue in detail.
I think it should be possible to get these tools working together with careful require order - require and initialize appsignal code first and then do the same with bugsnag.
These would be the steps:
- Disable automatic require in Gemfile via:
gem 'appsignal', require: false gem 'bugsnag', require: false
- Require appsignal first and then load bugsnag with disabled autoconfig:
# config/application.rb require "appsignal" # Let appsignal load all integrations and register rails initializers ENV["BUGSNAG_DISABLE_AUTOCONFIGURE"] = "1" require "bugsnag" Bugsnag.load_integration(:rails) Bugsnag.load_integration(:resque)
- Load bugsnag's rake integration only after appsignal has finished patching rake.
# config/application.rb initializer "bugsnag.load_rake_integration", after: "appsignal.configure_rails_initialization" do Bugsnag.load_integration(:rake) end
Unfortunately the last step is not possible in current version on bugsnag (6.17.0) as rake integration it is treated differently from others like resque, sidekiq or mongo.
Instead of being required with load_integration method call (https://github.com/bugsnag/bugsnag-ruby/blob/v6.17.0/lib/bugsnag.rb#L215-L222) it is required in Rails rake_tasks
block (https://github.com/bugsnag/bugsnag-ruby/blob/v6.17.0/lib/bugsnag/integrations/railtie.rb#L18).
When running a rake task mentioned rake_tasks
block is executed much sooner than initializers and that causes Rake::Task class to receive bugsnag's prepend module call before appsignal's alias method chain and that leads to stack level to deep exception mentioned in #577.
Please consider changing rake integration require logic to be more similar to others and users have more control when it is required.