From e12c0676ff3df123b8005d5689818ee49ea97348 Mon Sep 17 00:00:00 2001 From: "Luiz Felipe G. Pereira" Date: Tue, 29 Mar 2016 08:29:12 -0300 Subject: [PATCH 1/2] Adding a flag on Bugsnag::Railtie to control app_type overwriting Sometimes rails is ran as a dependency of another integration (eg. Sidekiq). But since the rails initializer runs after the integration, the app_type that is normally set ends up overwritten. Each integration has it's own logic that determines if rails is a dependency or the main actor. This flag can now be set by them to make sure the app_type won't change. --- lib/bugsnag/railtie.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bugsnag/railtie.rb b/lib/bugsnag/railtie.rb index 0b7ecf401..cdd76fb88 100644 --- a/lib/bugsnag/railtie.rb +++ b/lib/bugsnag/railtie.rb @@ -7,6 +7,8 @@ module Bugsnag class Railtie < Rails::Railtie + cattr_accessor :running_as_dependency + rake_tasks do require "bugsnag/rake" load "bugsnag/tasks/bugsnag.rake" @@ -49,7 +51,7 @@ class Railtie < Rails::Railtie ActiveRecord::Base.send(:include, Bugsnag::Rails::ActiveRecordRescue) end - Bugsnag.configuration.app_type = "rails" + Bugsnag.configuration.app_type = "rails" unless Bugsnag::Railtie.running_as_dependency end # Configure params_filters after initialization, so that rails initializers From 72389be14ef4ed6a47f6bf5c5a49de3b81436804 Mon Sep 17 00:00:00 2001 From: "Luiz Felipe G. Pereira" Date: Tue, 29 Mar 2016 08:30:05 -0300 Subject: [PATCH 2/2] Setting rails dependency flag when sidekiq is loaded through the CLI When the Sidekiq::CLI is defined, it means the "bin/sidekiq" was the entrypoint, so the app_type should be defined as sidekiq and not rails even if rails is loaded as a dependency Closes #285 --- lib/bugsnag/sidekiq.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bugsnag/sidekiq.rb b/lib/bugsnag/sidekiq.rb index 25709af8e..0ddbfe8ad 100644 --- a/lib/bugsnag/sidekiq.rb +++ b/lib/bugsnag/sidekiq.rb @@ -36,3 +36,7 @@ def call(worker, msg, queue) Bugsnag.configuration.internal_middleware.use(Bugsnag::Middleware::Sidekiq) Bugsnag.configuration.app_type = "sidekiq" + +if defined?(::Sidekiq::CLI) && defined?(Bugsnag::Railtie) + Bugsnag::Railtie.running_as_dependency = true +end