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

Added configuration option to disable autoconfiguration #419

Merged
merged 6 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions lib/bugsnag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
require "bugsnag/delivery/synchronous"
require "bugsnag/delivery/thread_queue"

# Rack is not bundled with the other integrations
# as it doesn't auto-configure when loaded
require "bugsnag/integrations/rack"

require "bugsnag/middleware/rack_request"
Expand All @@ -28,6 +30,7 @@

module Bugsnag
LOCK = Mutex.new
INTEGRATIONS = [:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que]

class << self
##
Expand Down Expand Up @@ -155,13 +158,28 @@ def start_session
def before_notify_callbacks
Bugsnag.configuration.request_data[:before_callbacks] ||= []
end
end
end

require "bugsnag/integrations/railtie" if defined?(Rails::Railtie)
[:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que].each do |integration|
begin
require "bugsnag/integrations/#{integration}"
rescue LoadError
# Attempts to load all integrations through auto-discovery
def load_integrations
require "bugsnag/integrations/railtie" if defined?(Rails::Railtie)
INTEGRATIONS.each do |integration|
begin
require "bugsnag/integrations/#{integration}"
rescue LoadError
end
end
end

# Load a specific integration
def load_integration(integration)
integration = :railtie if integration == :rails
if INTEGRATIONS.include?(integration) || integration == :railtie
require "bugsnag/integrations/#{integration}"
else
configuration.debug("Integration #{integration} is not currently supported")
end
end
end
end

Bugsnag.load_integrations unless ENV["BUGSNAG_DISABLE_AUTOCONFIGURE"]
67 changes: 67 additions & 0 deletions spec/bugsnag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,71 @@
expect(Bugsnag.configuration.logger).to have_received(:warn)
end
end

describe 'loading integrations' do
before do
module Kernel
REQUIRED = []
alias_method :old_require, :require
def require(path)
if path.include?("bugsnag/integrations/")
REQUIRED << path
else
old_require(path)
end
end
end
end

it 'attempts to load integrations' do
Kernel::REQUIRED = []
ENV["BUGSNAG_DISABLE_AUTOCONFIGURE"] = nil
load "./lib/bugsnag.rb"
Bugsnag::INTEGRATIONS.each do |integration|
expect(Kernel::REQUIRED).to include("bugsnag/integrations/#{integration}")
end
end

it 'does not load integrations when BUGSNAG_DISABLE_AUTOCONFIGURE is true' do
Kernel::REQUIRED = []
ENV["BUGSNAG_DISABLE_AUTOCONFIGURE"] = 'true'
load "./lib/bugsnag.rb"
expect(Kernel::REQUIRED).to eq(["bugsnag/integrations/rack"])
end

it 'loads all integrations if requested' do
Kernel::REQUIRED = []
expect(Kernel::REQUIRED).to eq([])
Bugsnag.load_integrations
Bugsnag::INTEGRATIONS.each do |integration|
expect(Kernel::REQUIRED).to include("bugsnag/integrations/#{integration}")
end
end

it 'loads singular integrations' do
Kernel::REQUIRED = []
expect(Kernel::REQUIRED).to eq([])
Bugsnag::INTEGRATIONS.each do |integration|
Kernel::REQUIRED = []
Bugsnag.load_integration(integration)
expect(Kernel::REQUIRED).to include("bugsnag/integrations/#{integration}")
end
end

it 'loads railtie for :rails or :railtie' do
Kernel::REQUIRED = []
Bugsnag.load_integration(:rails)
expect(Kernel::REQUIRED).to include("bugsnag/integrations/railtie")
Kernel::REQUIRED = []
Bugsnag.load_integration(:railtie)
expect(Kernel::REQUIRED).to include("bugsnag/integrations/railtie")
end

after do
module Kernel
alias_method :require, :old_require
end
Kernel.send(:remove_const, :REQUIRED)
end
end
end