diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index d983ad91f..3d8c0dba6 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -76,7 +76,10 @@ def capture_event(event, scope, hint = {}) # @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors. # @return [Event, nil] def event_from_exception(exception, hint = {}) - return unless @configuration.sending_allowed? && @configuration.exception_class_allowed?(exception) + return unless @configuration.sending_allowed? + + ignore_exclusions = hint.delete(:ignore_exclusions) { false } + return if !ignore_exclusions && !@configuration.exception_class_allowed?(exception) integration_meta = Sentry.integrations[hint[:integration]] diff --git a/sentry-ruby/lib/sentry/hub.rb b/sentry-ruby/lib/sentry/hub.rb index 8e58c60fc..9062195cc 100644 --- a/sentry-ruby/lib/sentry/hub.rb +++ b/sentry-ruby/lib/sentry/hub.rb @@ -122,6 +122,8 @@ def capture_exception(exception, **options, &block) options[:hint] ||= {} options[:hint][:exception] = exception + options[:hint][:ignore_exclusions] = options.delete(:ignore_exclusions) { false } + event = current_client.event_from_exception(exception, options[:hint]) return unless event diff --git a/sentry-ruby/spec/sentry/client_spec.rb b/sentry-ruby/spec/sentry/client_spec.rb index c28921a44..8599f0fea 100644 --- a/sentry-ruby/spec/sentry/client_spec.rb +++ b/sentry-ruby/spec/sentry/client_spec.rb @@ -333,6 +333,13 @@ module ExcTag; end expect(subject.event_from_exception(Sentry::Test::SubExc.new.tap { |x| x.extend(Sentry::Test::ExcTag) })).to be_nil end end + + context "when exclusions overridden with :ignore_exclusions" do + it 'returns Sentry::ErrorEvent' do + config.excluded_exceptions << Sentry::Test::BaseExc + expect(subject.event_from_exception(Sentry::Test::BaseExc.new, ignore_exclusions: true)).to be_a(Sentry::ErrorEvent) + end + end end context 'when the exception has a cause' do diff --git a/sentry-ruby/spec/sentry/hub_spec.rb b/sentry-ruby/spec/sentry/hub_spec.rb index 3b43000a2..0dfb75554 100644 --- a/sentry-ruby/spec/sentry/hub_spec.rb +++ b/sentry-ruby/spec/sentry/hub_spec.rb @@ -195,6 +195,14 @@ end.to change { transport.events.count }.by(1) end + it "takes ignore_exclusions option" do + configuration.excluded_exceptions << exception.class + + expect do + subject.capture_exception(exception, ignore_exclusions: true) + end.to change { transport.events.count }.by(1) + end + it_behaves_like "capture_helper" do let(:capture_helper) { :capture_exception } let(:capture_subject) { exception }