diff --git a/CHANGELOG.md b/CHANGELOG.md index f7b8dc70..d836a671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Airbrake Ruby Changelog ### master +* `add_filter` & `add_performance_filter` add filters even when Airbrake is not + configured ([#445](https://github.com/airbrake/airbrake-ruby/pull/445), + [#451](https://github.com/airbrake/airbrake-ruby/pull/451)) + ### [v4.0.1][v4.0.1] (Feburary 26, 2019) * Fixed bug in `Airbrake.configure` not setting `logger` properly diff --git a/lib/airbrake-ruby.rb b/lib/airbrake-ruby.rb index b18e7923..66e57311 100644 --- a/lib/airbrake-ruby.rb +++ b/lib/airbrake-ruby.rb @@ -77,71 +77,9 @@ module Airbrake # @!macro see_public_api_method # @see Airbrake.$0 - # NilNoticeNotifier is a no-op notice notifier, which mimics - # +Airbrake::NoticeNotifier+ and serves only the purpose of making the library - # API easier to use. - # - # @since v2.1.0 - class NilNoticeNotifier - # @macro see_public_api_method - def notify(_exception, _params = {}, &block); end - - # @macro see_public_api_method - def notify_sync(_exception, _params = {}, &block); end - - # @macro see_public_api_method - def add_filter(_filter = nil, &_block); end - - # @macro see_public_api_method - def delete_filter(_filter_class); end - - # @macro see_public_api_method - def build_notice(_exception, _params = {}); end - - # @macro see_public_api_method - def close; end - - # @macro see_public_api_method - def configured? - false - end - - # @macro see_public_api_method - def merge_context(_context); end - end - - # NilPerformanceNotifier is a no-op notifier, which mimics - # {Airbrake::PerformanceNotifier} and serves only the purpose of making the - # library API easier to use. - # - # @since v3.2.0 - class NilPerformanceNotifier - # @see Airbrake.notify_request - # @see Airbrake.notify_query - def notify(_performance_info); end - - # @see Airbrake.notify_request - # @see Airbrake.notify_query - def add_filter(_filter = nil, &_block); end - - # @see Airbrake.notify_request - # @see Airbrake.notify_query - def delete_filter(_filter_class); end - end - - # NilDeployNotifier is a no-op notifier, which mimics - # {Airbrake::DeployNotifier} and serves only the purpose of making the library - # API easier to use. - # - # @since v3.2.0 - class NilDeployNotifier - # @see Airbrake.notify_deploy - def notify(_deploy_info); end - end - - @notice_notifier = NilNoticeNotifier.new - @performance_notifier = NilPerformanceNotifier.new - @deploy_notifier = NilDeployNotifier.new + @performance_notifier = PerformanceNotifier.new + @notice_notifier = NoticeNotifier.new + @deploy_notifier = DeployNotifier.new class << self # Configures the Airbrake notifier. @@ -163,15 +101,11 @@ class << self def configure yield config = Airbrake::Config.instance - unless (result = config.validate.value) == :ok - raise Airbrake::Error, result['error'] + if (result = config.validate).rejected? + raise Airbrake::Error, result.value['error'] end Airbrake::Loggable.instance = config.logger - - @performance_notifier = PerformanceNotifier.new - @notice_notifier = NoticeNotifier.new - @deploy_notifier = DeployNotifier.new end # @return [Boolean] true if the notifier was configured, false otherwise @@ -219,7 +153,7 @@ def notify(exception, params = {}, &block) # @yield [notice] The notice to filter # @yieldparam [Airbrake::Notice] # @yieldreturn [void] - # @return [Hash{String=>String}] the reponse from the server + # @return [Airbrake::Promise] the reponse from the server # @see .notify def notify_sync(exception, params = {}, &block) @notice_notifier.notify_sync(exception, params, &block) diff --git a/spec/deploy_notifier_spec.rb b/spec/deploy_notifier_spec.rb index 75509aae..0bfc6102 100644 --- a/spec/deploy_notifier_spec.rb +++ b/spec/deploy_notifier_spec.rb @@ -10,6 +10,15 @@ expect(subject.notify({})).to be_an(Airbrake::Promise) end + context "when config is invalid" do + before { Airbrake::Config.instance.merge(project_id: nil) } + + it "returns a rejected promise" do + promise = subject.notify({}) + expect(promise).to be_rejected + end + end + context "when environment is configured" do before { Airbrake::Config.instance.merge(environment: 'fooenv') } diff --git a/spec/notice_notifier_spec.rb b/spec/notice_notifier_spec.rb index 7c3e2549..c24dd49e 100644 --- a/spec/notice_notifier_spec.rb +++ b/spec/notice_notifier_spec.rb @@ -107,6 +107,15 @@ sleep 1 end + context "when config is invalid" do + before { Airbrake::Config.instance.merge(project_id: nil) } + + it "returns a rejected promise" do + promise = subject.notify({}) + expect(promise).to be_rejected + end + end + context "when a notice is not ignored" do it "yields the notice" do expect { |b| subject.notify('ex', &b) } diff --git a/spec/performance_notifier_spec.rb b/spec/performance_notifier_spec.rb index 9cc75281..12aa7030 100644 --- a/spec/performance_notifier_spec.rb +++ b/spec/performance_notifier_spec.rb @@ -238,6 +238,15 @@ ).to have_been_made end + context "when config is invalid" do + before { Airbrake::Config.instance.merge(project_id: nil) } + + it "returns a rejected promise" do + promise = subject.notify({}) + expect(promise).to be_rejected + end + end + describe "payload grouping" do let(:flush_period) { 0.5 }