diff --git a/spec/lib/appsignal/config_spec.rb b/spec/lib/appsignal/config_spec.rb index 73a727f58..44f38a1df 100644 --- a/spec/lib/appsignal/config_spec.rb +++ b/spec/lib/appsignal/config_spec.rb @@ -405,7 +405,6 @@ def on_load :active => true, :push_api_key => "abc", :name => "TestApp", - :request_headers => kind_of(Array), :enable_minutely_probes => false ) end diff --git a/spec/lib/appsignal/hooks/activejob_spec.rb b/spec/lib/appsignal/hooks/activejob_spec.rb index ca6dd2a5f..8624f9ae8 100644 --- a/spec/lib/appsignal/hooks/activejob_spec.rb +++ b/spec/lib/appsignal/hooks/activejob_spec.rb @@ -72,10 +72,11 @@ ["perform_start.active_job", "perform.active_job"] end end + let(:options) { {} } before do ActiveJob::Base.queue_adapter = :inline - start_agent + start_agent(:options => options) Appsignal.internal_logger = test_logger(log) class ActiveJobTestJob < ActiveJob::Base def perform(*_args) @@ -209,10 +210,9 @@ def perform(*_args) end context "with activejob_report_errors set to none" do - it "does not report the error" do - start_agent("production") - Appsignal.config[:activejob_report_errors] = "none" + let(:options) { { :activejob_report_errors => "none" } } + it "does not report the error" do allow(Appsignal).to receive(:increment_counter) tags = { :queue => queue } expect(Appsignal).to receive(:increment_counter) @@ -228,10 +228,7 @@ def perform(*_args) if DependencyHelper.rails_version >= Gem::Version.new("7.1.0") context "with activejob_report_errors set to discard" do - before do - start_agent("production") - Appsignal.config[:activejob_report_errors] = "discard" - end + let(:options) { { :activejob_report_errors => "discard" } } it "does not report error on first failure" do with_test_adapter do @@ -351,9 +348,9 @@ def perform(*_args) end context "with params" do + let(:options) { { :filter_parameters => ["foo"] } } + it "filters the configured params" do - start_agent("production") - Appsignal.config[:filter_parameters] = ["foo"] queue_job(ActiveJobTestJob, method_given_args) transaction = last_transaction diff --git a/spec/lib/appsignal/hooks/gvl_spec.rb b/spec/lib/appsignal/hooks/gvl_spec.rb index 6b3e8bc43..b9fd54993 100644 --- a/spec/lib/appsignal/hooks/gvl_spec.rb +++ b/spec/lib/appsignal/hooks/gvl_spec.rb @@ -7,8 +7,9 @@ end end else + let(:options) { {} } before do - start_agent + start_agent(:options => options) end def expect_gvltools_require @@ -100,8 +101,9 @@ def self.enable describe "#install" do context "with enable_gvl_global_timer" do + let(:options) { { :enable_gvl_global_timer => true } } + it "enables the GVL global timer" do - Appsignal.config[:enable_gvl_global_timer] = true expect(::GVLTools::GlobalTimer).to receive(:enable) described_class.new.install @@ -109,8 +111,9 @@ def self.enable end context "without enable_gvl_global_timer" do + let(:options) { { :enable_gvl_global_timer => false } } + it "does not enable the GVL global timer" do - Appsignal.config[:enable_gvl_global_timer] = false expect(::GVLTools::GlobalTimer).not_to receive(:enable) described_class.new.install @@ -118,8 +121,9 @@ def self.enable end context "with enable_gvl_waiting_threads" do + let(:options) { { :enable_gvl_waiting_threads => true } } + it "enables the GVL waiting threads" do - Appsignal.config[:enable_gvl_global_timer] = true expect(::GVLTools::WaitingThreads).to receive(:enable) described_class.new.install @@ -127,8 +131,9 @@ def self.enable end context "without enable_gvl_waiting_threads" do + let(:options) { { :enable_gvl_waiting_threads => false } } + it "does not enable the GVL waiting threads" do - Appsignal.config[:enable_gvl_waiting_threads] = false expect(::GVLTools::WaitingThreads).not_to receive(:enable) described_class.new.install diff --git a/spec/lib/appsignal/hooks/http_spec.rb b/spec/lib/appsignal/hooks/http_spec.rb index 07ace5cc8..f7c6384dc 100644 --- a/spec/lib/appsignal/hooks/http_spec.rb +++ b/spec/lib/appsignal/hooks/http_spec.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true describe Appsignal::Hooks::HttpHook do - before { start_agent } + let(:options) { {} } + before { start_agent(:options => options) } if DependencyHelper.http_present? context "with instrument_http_rb set to true" do @@ -18,8 +19,7 @@ end context "with instrument_http_rb set to false" do - before { Appsignal.config.config_hash[:instrument_http_rb] = false } - after { Appsignal.config.config_hash[:instrument_http_rb] = true } + let(:options) { { :instrument_http_rb => false } } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/net_http_spec.rb b/spec/lib/appsignal/hooks/net_http_spec.rb index 2cb65bf99..8a96dd05d 100644 --- a/spec/lib/appsignal/hooks/net_http_spec.rb +++ b/spec/lib/appsignal/hooks/net_http_spec.rb @@ -1,5 +1,6 @@ describe Appsignal::Hooks::NetHttpHook do - before { start_agent } + let(:options) { {} } + before { start_agent(:options => options) } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } @@ -9,8 +10,7 @@ end context "with Net::HTTP instrumentation disabled" do - before { Appsignal.config.config_hash[:instrument_net_http] = false } - after { Appsignal.config.config_hash[:instrument_net_http] = true } + let(:options) { { :instrument_net_http => false } } it { is_expected.to be_falsy } end diff --git a/spec/lib/appsignal/hooks/rake_spec.rb b/spec/lib/appsignal/hooks/rake_spec.rb index 6d4c8413b..2bdd95af6 100644 --- a/spec/lib/appsignal/hooks/rake_spec.rb +++ b/spec/lib/appsignal/hooks/rake_spec.rb @@ -4,8 +4,9 @@ let(:helper) { Appsignal::Integrations::RakeIntegrationHelper } let(:task) { Rake::Task.new("task:name", Rake::Application.new) } let(:arguments) { Rake::TaskArguments.new(["foo"], ["bar"]) } + let(:options) { {} } before do - start_agent + start_agent(:options => options) allow(Kernel).to receive(:at_exit) end around { |example| keep_transactions { example.run } } @@ -30,9 +31,7 @@ def perform end context "with :enable_rake_performance_instrumentation == false" do - before do - Appsignal.config[:enable_rake_performance_instrumentation] = false - end + let(:options) { { :enable_rake_performance_instrumentation => false } } it "creates no transaction" do expect { perform }.to_not(change { created_transactions.count }) @@ -49,9 +48,7 @@ def perform end context "with :enable_rake_performance_instrumentation == true" do - before do - Appsignal.config[:enable_rake_performance_instrumentation] = true - end + let(:options) { { :enable_rake_performance_instrumentation => true } } it "creates a transaction" do expect { perform }.to(change { created_transactions.count }.by(1)) diff --git a/spec/lib/appsignal/hooks/redis_client_spec.rb b/spec/lib/appsignal/hooks/redis_client_spec.rb index 45ec7d432..888af0737 100644 --- a/spec/lib/appsignal/hooks/redis_client_spec.rb +++ b/spec/lib/appsignal/hooks/redis_client_spec.rb @@ -1,6 +1,7 @@ describe Appsignal::Hooks::RedisClientHook do + let(:options) { {} } before do - start_agent + start_agent(:options => options) end if DependencyHelper.redis_client_present? @@ -30,9 +31,7 @@ context "with rest-client gem" do describe "integration" do - before do - Appsignal.config.config_hash[:instrument_redis] = true - end + let(:options) { { :instrument_redis => true } } context "install" do before do @@ -115,9 +114,7 @@ def write(_commands) if DependencyHelper.hiredis_client_present? context "with hiredis driver" do describe "integration" do - before do - Appsignal.config.config_hash[:instrument_redis] = true - end + let(:options) { { :instrument_redis => true } } context "install" do before do @@ -200,9 +197,7 @@ def write(_commands) end context "with instrumentation disabled" do - before do - Appsignal.config.config_hash[:instrument_redis] = false - end + let(:options) { { :instrument_redis => false } } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/redis_spec.rb b/spec/lib/appsignal/hooks/redis_spec.rb index 3f84ac099..a4edab721 100644 --- a/spec/lib/appsignal/hooks/redis_spec.rb +++ b/spec/lib/appsignal/hooks/redis_spec.rb @@ -1,5 +1,6 @@ describe Appsignal::Hooks::RedisHook do - before { start_agent } + let(:options) { {} } + before { start_agent(:options => options) } if DependencyHelper.redis_present? context "with redis" do @@ -22,9 +23,7 @@ end describe "integration" do - before do - Appsignal.config.config_hash[:instrument_redis] = true - end + let(:options) { { :instrument_redis => true } } context "install" do before do @@ -103,9 +102,7 @@ def write(_commands) end context "with instrumentation disabled" do - before do - Appsignal.config.config_hash[:instrument_redis] = false - end + let(:options) { { :instrument_redis => false } } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/resque_spec.rb b/spec/lib/appsignal/hooks/resque_spec.rb index d9c155881..4327a85ad 100644 --- a/spec/lib/appsignal/hooks/resque_spec.rb +++ b/spec/lib/appsignal/hooks/resque_spec.rb @@ -25,8 +25,9 @@ def perform_rescue_job(klass, options = {}) let(:queue) { "default" } let(:namespace) { Appsignal::Transaction::BACKGROUND_JOB } + let(:options) { {} } before do - start_agent + start_agent(:options => options) class ResqueTestJob def self.perform(*_args) @@ -82,10 +83,7 @@ def self.perform end context "with arguments" do - before do - start_agent("production") - Appsignal.config[:filter_parameters] = ["foo"] - end + let(:options) { { :filter_parameters => ["foo"] } } it "filters out configured arguments" do perform_rescue_job( diff --git a/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb b/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb index 19cab5660..29144d9df 100644 --- a/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +++ b/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb @@ -15,7 +15,8 @@ def self.plugins require "appsignal/integrations/delayed_job_plugin" end after(:context) { Object.send(:remove_const, :Delayed) } - before { start_agent } + let(:options) { {} } + before { start_agent(:options => options) } # We haven't found a way to test the hooks, we'll have to do that manually @@ -82,10 +83,7 @@ def perform end context "with parameter filtering" do - before do - start_agent("production") - Appsignal.config[:filter_parameters] = ["foo"] - end + let(:options) { { :filter_parameters => ["foo"] } } it "filters selected arguments" do perform @@ -271,10 +269,7 @@ def self.appsignal_name end context "with parameter filtering" do - before do - start_agent("production") - Appsignal.config[:filter_parameters] = ["foo"] - end + let(:options) { { :filter_parameters => ["foo"] } } it "filters selected arguments" do perform diff --git a/spec/lib/appsignal/integrations/shoryuken_spec.rb b/spec/lib/appsignal/integrations/shoryuken_spec.rb index 4a68f3ec9..bc6df8a0b 100644 --- a/spec/lib/appsignal/integrations/shoryuken_spec.rb +++ b/spec/lib/appsignal/integrations/shoryuken_spec.rb @@ -9,7 +9,8 @@ class DemoShoryukenWorker let(:queue) { "some-funky-queue-name" } let(:sqs_msg) { double(:message_id => "msg1", :attributes => {}) } let(:body) { {} } - before { start_agent } + let(:options) { {} } + before { start_agent(:options => options) } around { |example| keep_transactions { example.run } } def perform_shoryuken_job(&block) @@ -60,10 +61,7 @@ def perform_shoryuken_job(&block) end context "with parameter filtering" do - before do - start_agent("production") - Appsignal.config[:filter_parameters] = ["foo"] - end + let(:options) { { :filter_parameters => ["foo"] } } it "filters selected arguments" do perform_shoryuken_job diff --git a/spec/lib/appsignal/integrations/sidekiq_spec.rb b/spec/lib/appsignal/integrations/sidekiq_spec.rb index 83feac864..4829dc727 100644 --- a/spec/lib/appsignal/integrations/sidekiq_spec.rb +++ b/spec/lib/appsignal/integrations/sidekiq_spec.rb @@ -1,7 +1,11 @@ require "appsignal/integrations/sidekiq" describe Appsignal::Integrations::SidekiqDeathHandler do - before { start_agent } + let(:options) { {} } + before do + stub_const("Sidekiq::VERSION", "7.1.0") + start_agent(:options => options) + end around { |example| keep_transactions { example.run } } let(:exception) do @@ -28,10 +32,8 @@ def expect_no_error_on_transaction end context "when sidekiq_report_errors = none" do - before do - Appsignal.config[:sidekiq_report_errors] = "none" - call_handler - end + let(:options) { { :sidekiq_report_errors => "none" } } + before { call_handler } it "doesn't track the error on the transaction" do expect_no_error_on_transaction @@ -39,10 +41,8 @@ def expect_no_error_on_transaction end context "when sidekiq_report_errors = all" do - before do - Appsignal.config[:sidekiq_report_errors] = "all" - call_handler - end + let(:options) { { :sidekiq_report_errors => "all" } } + before { call_handler } it "doesn't track the error on the transaction" do expect_no_error_on_transaction @@ -50,10 +50,8 @@ def expect_no_error_on_transaction end context "when sidekiq_report_errors = discard" do - before do - Appsignal.config[:sidekiq_report_errors] = "discard" - call_handler - end + let(:options) { { :sidekiq_report_errors => "discard" } } + before { call_handler } it "records each occurrence of the error on the transaction" do expect_error_on_transaction @@ -62,7 +60,8 @@ def expect_no_error_on_transaction end describe Appsignal::Integrations::SidekiqErrorHandler do - before { start_agent } + let(:options) { {} } + before { start_agent(:options => options) } around { |example| keep_transactions { example.run } } let(:exception) do @@ -96,7 +95,7 @@ def expect_report_internal_error end context "when sidekiq_report_errors = none" do - before { Appsignal.config[:sidekiq_report_errors] = "none" } + let(:options) { { :sidekiq_report_errors => "none" } } it "tracks the error on a new transaction" do expect_report_internal_error @@ -104,7 +103,7 @@ def expect_report_internal_error end context "when sidekiq_report_errors = all" do - before { Appsignal.config[:sidekiq_report_errors] = "all" } + let(:options) { { :sidekiq_report_errors => "all" } } it "tracks the error on a new transaction" do expect_report_internal_error @@ -112,7 +111,7 @@ def expect_report_internal_error end context "when sidekiq_report_errors = discard" do - before { Appsignal.config[:sidekiq_report_errors] = "discard" } + let(:options) { { :sidekiq_report_errors => "discard" } } it "tracks the error on a new transaction" do expect_report_internal_error @@ -143,10 +142,8 @@ def expect_no_error_on_transaction end context "when sidekiq_report_errors = none" do - before do - Appsignal.config[:sidekiq_report_errors] = "none" - call_handler - end + let(:options) { { :sidekiq_report_errors => "none" } } + before { call_handler } it "doesn't track the error on the transaction" do expect_no_error_on_transaction @@ -155,10 +152,8 @@ def expect_no_error_on_transaction end context "when sidekiq_report_errors = all" do - before do - Appsignal.config[:sidekiq_report_errors] = "all" - call_handler - end + let(:options) { { :sidekiq_report_errors => "all" } } + before { call_handler } it "records each occurrence of the error on the transaction" do expect_error_on_transaction @@ -167,10 +162,8 @@ def expect_no_error_on_transaction end context "when sidekiq_report_errors = discard" do - before do - Appsignal.config[:sidekiq_report_errors] = "discard" - call_handler - end + let(:options) { { :sidekiq_report_errors => "discard" } } + before { call_handler } it "doesn't track the error on the transaction" do expect_no_error_on_transaction @@ -222,8 +215,9 @@ class DelayedTestClass; end end let(:plugin) { Appsignal::Integrations::SidekiqMiddleware.new } let(:log) { StringIO.new } + let(:options) { {} } before do - start_agent + start_agent(:options => options) Appsignal.internal_logger = test_logger(log) end around { |example| keep_transactions { example.run } } @@ -242,10 +236,7 @@ class DelayedTestClass; end end context "with parameter filtering" do - before do - start_agent("production") - Appsignal.config[:filter_parameters] = ["foo"] - end + let(:options) { { :filter_parameters => ["foo"] } } it "filters selected arguments" do perform_sidekiq_job @@ -384,7 +375,6 @@ class DelayedTestClass; end include RailsHelper it "reports the worker name as the action, copies the namespace and tags" do - start_agent("production") with_rails_error_reporter do perform_sidekiq_job do Appsignal.tag_job("test_tag" => "value") diff --git a/spec/lib/appsignal/transaction_spec.rb b/spec/lib/appsignal/transaction_spec.rb index 98b23781a..ac0d6c558 100644 --- a/spec/lib/appsignal/transaction_spec.rb +++ b/spec/lib/appsignal/transaction_spec.rb @@ -1,8 +1,9 @@ describe Appsignal::Transaction do + let(:options) { {} } let(:time) { Time.at(fixed_time) } before do - start_agent + start_agent(:options => options) Timecop.freeze(time) end after { Timecop.return } @@ -323,7 +324,7 @@ end context "with AppSignal filtering" do - before { Appsignal.config.config_hash[:filter_parameters] = %w[foo] } + let(:options) { { :filter_parameters => %w[foo] } } it "returns sanitized custom params" do transaction.set_params("foo" => "value", "baz" => "bat") @@ -439,12 +440,15 @@ expect(transaction).to include_session_data(arg_data) end - it "does not include filtered out session data" do - Appsignal.config[:filter_session_data] = ["filtered_key"] - transaction.set_session_data("data" => "value1", "filtered_key" => "filtered_value") + context "with filter_session_data" do + let(:options) { { :filter_session_data => ["filtered_key"] } } - transaction._sample - expect(transaction).to include_session_data("data" => "value1") + it "does not include filtered out session data" do + transaction.set_session_data("data" => "value1", "filtered_key" => "filtered_value") + + transaction._sample + expect(transaction).to include_session_data("data" => "value1") + end end it "logs an error if an error occurred storing the session data" do @@ -563,12 +567,15 @@ expect(transaction).to include_environment(arg_data) end - it "does not include filtered out headers" do - Appsignal.config[:request_headers] = ["MY_HEADER"] - transaction.set_headers("MY_HEADER" => "value1", "filtered_key" => "filtered_value") + context "with request_headers options" do + let(:options) { { :request_headers => ["MY_HEADER"] } } - transaction._sample - expect(transaction).to include_environment("MY_HEADER" => "value1") + it "does not include filtered out headers" do + transaction.set_headers("MY_HEADER" => "value1", "filtered_key" => "filtered_value") + + transaction._sample + expect(transaction).to include_environment("MY_HEADER" => "value1") + end end it "logs an error if an error occurred storing the headers" do @@ -975,8 +982,7 @@ end context "when filter_metadata includes metadata key" do - before { Appsignal.config[:filter_metadata] = ["filter_key"] } - after { Appsignal.config[:filter_metadata] = [] } + let(:options) { { :filter_metadata => ["filter_key"] } } it "does not set the metadata on the transaction" do transaction.set_metadata(:filter_key, "filtered value") diff --git a/spec/support/fixtures/projects/valid/config/appsignal.yml b/spec/support/fixtures/projects/valid/config/appsignal.yml index 8a345a432..a8b467a54 100644 --- a/spec/support/fixtures/projects/valid/config/appsignal.yml +++ b/spec/support/fixtures/projects/valid/config/appsignal.yml @@ -1,13 +1,6 @@ default: &defaults push_api_key: "abc" name: "TestApp" - request_headers: [ - "HTTP_ACCEPT", "HTTP_ACCEPT_CHARSET", "HTTP_ACCEPT_ENCODING", - "HTTP_ACCEPT_LANGUAGE", "HTTP_CACHE_CONTROL", "HTTP_CONNECTION", - "CONTENT_LENGTH", "PATH_INFO", "HTTP_RANGE", "HTTP_REFERER", - "REQUEST_METHOD", "REQUEST_PATH", "SERVER_NAME", "SERVER_PORT", - "SERVER_PROTOCOL", "HTTP_USER_AGENT" - ] enable_minutely_probes: false production: diff --git a/spec/support/helpers/config_helpers.rb b/spec/support/helpers/config_helpers.rb index 9e4d83c53..184faa5b9 100644 --- a/spec/support/helpers/config_helpers.rb +++ b/spec/support/helpers/config_helpers.rb @@ -1,4 +1,8 @@ module ConfigHelpers + def with_config(_options) + A + end + def project_fixture_path File.expand_path( File.join(File.dirname(__FILE__), "../fixtures/projects/valid") @@ -22,8 +26,8 @@ def project_fixture_config( # rubocop:disable Metrics/ParameterLists end module_function :project_fixture_config, :project_fixture_path - def start_agent(env = "production") - Appsignal._config = project_fixture_config(env) + def start_agent(env: "production", options: {}) + Appsignal._config = project_fixture_config(env, options) Appsignal.start end end