-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
The report_rescued_exceptions
option is not honoured in a Rails production environment
#1840
Comments
@matthieuprat I checked your test case and it does fail. However, I don't think it's captured through the request env. I used ruby/debug's tracer to see how the exception flows # the first 2 command checks I'm with the right settings
# the last tells the debugger to trace exception raised with the RuntimeError pattern
debugger(do: "Rails.application.config.consider_all_requests_local ;; Sentry.configuration.rails.report_rescued_exceptions ;; trace exception /RuntimeError/")
get "/exception" And here's the result: (rdbg:binding.break) Rails.application.config.consider_all_requests_local
false
(rdbg:binding.break) Sentry.configuration.rails.report_rescued_exceptions
false
(rdbg:binding.break) trace exception /RuntimeError/
Enable ExceptionTracer (enabled) with pattern /RuntimeError/
DEBUGGER (trace/exception) #th:1 #depth:133 #<RuntimeError: An unhandled exception!> at /Users/st0012/projects/sentry-ruby/sentry-rails/spec/dummy/test_rails_app/apps/7-0.rb:76
DEBUGGER (trace/exception) #th:1 #depth:127 #<RuntimeError: An unhandled exception!> at /Users/st0012/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.3/lib/action_controller/metal/rescue.rb:25
DEBUGGER (trace/exception) #th:1 #depth:126 #<RuntimeError: An unhandled exception!> at /Users/st0012/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.3/lib/action_controller/metal/instrumentation.rb:73
DEBUGGER (trace/exception) #th:1 #depth:124 #<RuntimeError: An unhandled exception!> at /Users/st0012/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/activesupport-7.0.3/lib/active_support/notifications/instrumenter.rb:28
DEBUGGER (trace/exception) #th:1 #depth:97 #<RuntimeError: An unhandled exception!> at /Users/st0012/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.3/lib/action_dispatch/middleware/callbacks.rb:30
DEBUGGER (trace/exception) #th:1 #depth:97 #<RuntimeError: An unhandled exception!> at /Users/st0012/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.3/lib/action_dispatch/middleware/executor.rb:18
DEBUGGER (trace/exception) #th:1 #depth:96 #<RuntimeError: An unhandled exception!> at /Users/st0012/projects/sentry-ruby/sentry-rails/lib/sentry/rails/rescued_exception_interceptor.rb:15
DEBUGGER (trace/exception) #th:1 #depth:96 #<RuntimeError: An unhandled exception!> at /Users/st0012/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/actionpack-7.0.3/lib/action_dispatch/middleware/debug_exceptions.rb:72
DEBUGGER (trace/exception) #th:1 #depth:94 #<RuntimeError: An unhandled exception!> at /Users/st0012/projects/sentry-ruby/sentry-ruby/lib/sentry/rack/capture_exceptions.rb:33
doesn't report rescued exceptions (FAILED - 1) If you check the last few traces, you can see it's actually reported via raise/rescue:
But perhaps the
The exception raising flow still presents. So in this case ( |
Yes, I think you're right; since 7a3a86b, the exception is no longer captured via the request env. It just bubbles up to the Before 7a3a86b, the My point being that the issue doesn't seem to be new. And fixing it might actually be a breaking change for some people. Hence why I was wondering whether it would make sense to update the docs instead. |
I don't understand why should we update the doc. In the case, the exception was re-raised by the Rails itself, therefore it's not actually rescued (or swallowed to be precise). So the SDK doesn't report a rescued exception, it's a raised exception. |
Hm, I don't think this is the case. In a production environment (more precisely, when To clarify, the flow is the following:
In essence, the exception is swallowed by the |
Yes you're correct. Sorry that I was scoped by the cause you mentioned at the beginning. I think this is a bug and I'll find a way to fix it. Thanks for detailed report 👍 |
When an exception is going to be swallowed by ShowExceptions middleware, we should check the report_rescued_exceptions config before reporting it. See #1840 for more details
No worries, thank you for the quick follow-up! |
Issue Description
Setting the
report_rescued_exceptions
option tofalse
doesn't seem to be effective in a Rails production environment: exceptions rescued by theActionDispatch::ShowExceptions
middleware are reported, but as per the documentation, they shouldn't.I originally thought this bug was introduced in 7a3a86b but on closer look, I'm actually not sure this is the case. Before this commit, the
CaptureExceptions
middleware was wrapping theShowExceptions
middleware, so one would be tempted to think that if exceptions were swallowed by the latter, the former wouldn't report them. However, theShowExceptions
middleware sets the exception it swallows in theaction_dispatch.exception
header and theCaptureExceptions
middleware reads this value back to report the exception (regardless ofreport_rescued_exceptions
).In short, I'm not sure whether this is an actual bug or whether the documentation is wrong.
Reproduction Steps
Add this spec to
sentry-rails/spec/sentry/rails_spec.rb
:Expected Behavior
The spec should pass.
Actual Behavior
The spec fails with the following message:
Ruby Version
3.0.2
SDK Version
5.3.0
Integration and Its Version
Rails v6.1.4.4
Sentry Config
The text was updated successfully, but these errors were encountered: