Skip to content

Commit

Permalink
Allow ignoring excluded_exceptions when manually capturing exceptions (
Browse files Browse the repository at this point in the history
…#2007)

* Allow ignoring excluded_exceptions when manually capturing exceptions

* Update sentry-ruby/lib/sentry/client.rb

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Incorporate PR test feedback

* Put exclusion ignore param into hint

---------

Co-authored-by: Stan Lo <stan001212@gmail.com>
  • Loading branch information
ty-porter and st0012 authored Mar 20, 2023
1 parent 9c90d2d commit 1a2d682
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down
2 changes: 2 additions & 0 deletions sentry-ruby/lib/sentry/hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions sentry-ruby/spec/sentry/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions sentry-ruby/spec/sentry/hub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 1a2d682

Please sign in to comment.