Skip to content

Respect report_rescued_exceptions config #1847

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

Merged
merged 2 commits into from
Jul 18, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
```
- Prepare for Rails 7.1's error reporter API change [#1834](https://github.com/getsentry/sentry-ruby/pull/1834)

### Bug Fixes

- Respect `report_rescued_exceptions` config [#1847](https://github.com/getsentry/sentry-ruby/pull/1847)
- Fixes [#1840](https://github.com/getsentry/sentry-ruby/issues/1840)

### Refactoring

- Move envelope item processing/trimming logic to the Item class [#1824](https://github.com/getsentry/sentry-ruby/pull/1824)
Expand Down
9 changes: 7 additions & 2 deletions sentry-rails/lib/sentry/rails/capture_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ def transaction_op
"rails.request".freeze
end

def capture_exception(exception)
def capture_exception(exception, env)
request = ActionDispatch::Request.new(env)

# the exception will be swallowed by ShowExceptions middleware
return if request.show_exceptions? && !Sentry.configuration.rails.report_rescued_exceptions

current_scope = Sentry.get_current_scope

if original_transaction = current_scope.rack_env["sentry.original_transaction"]
if original_transaction = env["sentry.original_transaction"]
current_scope.set_transaction_name(original_transaction)
end

Expand Down
29 changes: 19 additions & 10 deletions sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,11 @@
end
end

context "with development config" do
before do
make_basic_app do |config, app|
app.config.consider_all_requests_local = true
config.rails.report_rescued_exceptions = report_rescued_exceptions
end
end

RSpec.shared_examples "report_rescued_exceptions" do
context "with report_rescued_exceptions = true" do
let(:report_rescued_exceptions) { true }
before do
Sentry.configuration.rails.report_rescued_exceptions = true
end

it "captures exceptions" do
get "/exception"
Expand All @@ -105,7 +100,9 @@
end

context "with report_rescued_exceptions = false" do
let(:report_rescued_exceptions) { false }
before do
Sentry.configuration.rails.report_rescued_exceptions = false
end

it "doesn't report rescued exceptions" do
get "/exception"
Expand All @@ -115,13 +112,25 @@
end
end

context "with development config" do
before do
make_basic_app do |config, app|
app.config.consider_all_requests_local = true
end
end

include_examples "report_rescued_exceptions"
end

context "with production config" do
before do
make_basic_app do |config, app|
app.config.consider_all_requests_local = false
end
end

include_examples "report_rescued_exceptions"

it "doesn't do anything on a normal route" do
get "/"

Expand Down
6 changes: 3 additions & 3 deletions sentry-ruby/lib/sentry/rack/capture_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def call(env)
finish_transaction(transaction, 500)
raise # Don't capture Sentry errors
rescue Exception => e
capture_exception(e)
capture_exception(e, env)
finish_transaction(transaction, 500)
raise
end

exception = collect_exception(env)
capture_exception(exception) if exception
capture_exception(exception, env) if exception

finish_transaction(transaction, response[0])

Expand All @@ -53,7 +53,7 @@ def transaction_op
"rack.request".freeze
end

def capture_exception(exception)
def capture_exception(exception, _env)
Sentry.capture_exception(exception)
end

Expand Down