-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
Exceptions not sent to Sentry from development environment (better_errors) #738
Comments
I'm going to need some additional reproduction steps. Using a blank "rails new" application in development (so class HelloController < ApplicationController
def exception
raise "Hi!"
end
end |
You can try modifying this script to reproduce your issue. |
@nateberkopec Same here with an Ruby on Rails
specs:
BTW, if I send a command to capture message that works: Raven.capture_message("Something went very wrong") Your example above does not... |
Please feel free to reopen with reproduction steps. |
I have same problem and for me it's caused by Simply add better_errors gem to your script to reproduce. |
I also have the same issue using |
Hi, I also encountered the same issue. What I did was to declare this in my controller
and have the following set in my sentry.rb
If I invoke Raven.send_capture(), then it works. |
better_errors
better_errors
better_errors
)
better_errors
)
Hello, I stumbled against this "conflict" with the BetterErrors middleware too. IMHO, given that the BetterErrors middleware is inserted after the DebugExceptions and exceptions for some reason never reach DebugExceptions (is as if the bubbling goes the other way in the stack?), maybe we should consider either monkey patching the BetterErrors::Middleware#protected_app_call or move the Rack middleware to the end instead that at the beginning. |
I'm seeing this issue as well and I can reproduce the weirdness 100% of the time in my development env. With As (e) |
+1. Would be nice to have this be compatible with better_errors. |
Raven inserts its middleware, BetterErrors inserts its middleware, In order to prevent So, one way to add compatibility for BetterErrors to Raven is to patch In a Rails initializer, # https://github.com/getsentry/raven-ruby/issues/738#issuecomment-592720365
if defined?(::BetterErrors::Middleware)
module BetterErrorsRavenCompatibility
def show_error_page(env, exception = nil)
begin
Raven::Rack.capture_exception exception, env if exception
rescue StandardError # rubocop:disable Lint/HandleExceptions
end
super
end
end
Rails.application.config.after_initialize do
if Raven.configuration.rails_report_rescued_exceptions
BetterErrors::Middleware.prepend BetterErrorsRavenCompatibility
end
end
end This works, but since it's basically a monkey-patch to BetterErrors, it relies on private API that might change between versions. It's not clear what the best long-term fix is, though. It doesn't really make sense for BetterErrors to automatically detect Raven and to automatically report the error. Similarly, I could understand if maintainers of Raven didn't want to add custom code for maintaining BetterErrors support. The right fix might just be to add documentation for Raven somewhere that includes a patch like this. |
@cjlarose I don't maintain this anymore (someone else at Sentry does) but just wanted to leave a comment: you leave some of the amazingly clear and detailed explanations of bugs on OSS repos that I have ever seen. |
We encounter the same issue in our app with better_errors (for now we use the mentioned workaround, thanks!). @st0012 what is the intended solution considering the "wontfix" label added on Sep 17? |
this is not really a sentry SDK's issue imo (nor better_error's though). this kind of issue can happen when any Ruby gem's middleware tries to rescue errors before Sentry's middleware (which is not hard to do as the Sentry's middleware will be placed at the very front). and from a SDK's point of view, we can't possibly detect and resolve each of those cases from the SDK itself. so imo the best solution should be to have a standalone gem, like but given that this is not a bug in SDK itself + we still have higher priority tasks, we don't plan to add the additional support at the moment. this is why it's marked as |
OK. For info here is our initializer after updating from sentry-raven to sentry-ruby 4.1.1: # https://github.com/getsentry/sentry-ruby/issues/738#issuecomment-750323266
if defined?(::BetterErrors::Middleware)
module BetterErrorsSentryCompatibility
def show_error_page(env, exception = nil)
begin
Sentry::Rack.capture_exception exception, env if exception
rescue StandardError # rubocop:disable Lint/HandleExceptions
end
super
end
end
Rails.application.config.after_initialize do
if Sentry.configuration.rails.report_rescued_exceptions
BetterErrors::Middleware.prepend BetterErrorsSentryCompatibility
end
end
end |
@sedubois thanks for posting an updated version 👍 |
There are a few drawbacks on the method override approach: 1. It's hard to properly cleanup the patched method after tests. This makes setting app for different setups very hard. 2. We need to target specific middlewares to make it work. If there's another exception-rescuing middleware in the middle that aren't patched, the exception would still not be reported. See #738 So this commit inserts a new middleware for capturing rescued exceptions. It works like this: - The new middleware should be the last middleware of the app. - When `config.rails.report_rescued_exceptions = true` there's an exception raised 1. the exception will be stored in the request env under the `"sentry.rescued_exception"` key. 2. the CaptureExceptions middleware will detect that env and report the exception. - When `config.rails.report_rescued_exceptions = false` there's an exception raised - It doesn't store the exception in request env, so if the exception is captured by other middlewares, it won't be reported. Although the approach is very different than the old one, but it should be able to solve the same problem and cause less bugs.
There are a few drawbacks to the method override approach: 1. It's hard to properly clean up the patched method after tests. This makes setting apps for different setups very hard. 2. We need to target specific middlewares to make it work. If there's another exception-rescuing middleware in the middle that isn't patched, the exception would still not be reported. See #738 So this commit inserts a new middleware for capturing rescued exceptions. It works like this: - The new middleware should be the last middleware of the app. - When `config.rails.report_rescued_exceptions = true` there's an exception raised 1. the exception will be stored in the request env under the `"sentry.rescued_exception"` key. 2. the CaptureExceptions middleware will detect that env and report the exception. - When `config.rails.report_rescued_exceptions = false` there's an exception raised - It doesn't store the exception in request env, so if the exception is captured by other middlewares, it won't be reported. Although the approach is very different than the old one, it should be able to solve the same problem and cause fewer bugs.
Good news: I came up with another way to address these kinds of issue in #1168. The PR should fix this issue and will be included in version However, I won't backport this fix to the old |
There are a few drawbacks to the method override approach: 1. It's hard to properly clean up the patched method after tests. This makes setting apps for different setups very hard. 2. We need to target specific middlewares to make it work. If there's another exception-rescuing middleware in the middle that isn't patched, the exception would still not be reported. See #738 So this commit inserts a new middleware for capturing rescued exceptions. It works like this: - The new middleware should be the last middleware of the app. - When `config.rails.report_rescued_exceptions = true` there's an exception raised 1. the exception will be stored in the request env under the `"sentry.rescued_exception"` key. 2. the CaptureExceptions middleware will detect that env and report the exception. - When `config.rails.report_rescued_exceptions = false` there's an exception raised - It doesn't store the exception in request env, so if the exception is captured by other middlewares, it won't be reported. Although the approach is very different than the old one, it should be able to solve the same problem and cause fewer bugs.
#1168) * Allow configuring test app dynamically as well * Group test cases base on prod/dev setup * Use middleware instead of method override to handle rescued exceptions There are a few drawbacks to the method override approach: 1. It's hard to properly clean up the patched method after tests. This makes setting apps for different setups very hard. 2. We need to target specific middlewares to make it work. If there's another exception-rescuing middleware in the middle that isn't patched, the exception would still not be reported. See #738 So this commit inserts a new middleware for capturing rescued exceptions. It works like this: - The new middleware should be the last middleware of the app. - When `config.rails.report_rescued_exceptions = true` there's an exception raised 1. the exception will be stored in the request env under the `"sentry.rescued_exception"` key. 2. the CaptureExceptions middleware will detect that env and report the exception. - When `config.rails.report_rescued_exceptions = false` there's an exception raised - It doesn't store the exception in request env, so if the exception is captured by other middlewares, it won't be reported. Although the approach is very different than the old one, it should be able to solve the same problem and cause fewer bugs. * Remove DebugExceptionsCatcher
With the latest sentry-rails v4.1.2, errors weren't being sent in development when I explicitly specified This is the default (it uses RAILS_ENV) so I removed the config.environment line and it fixed the problem for me. Strange but happy it's working now. |
In development environment, only when exception is captured explicitly using
Raven.capture
, the exception is getting sent to Sentry and shown in the list of exceptions.But if
config.consider_all_requests_local = false
in development.rb, the exceptions are sent.Related issue - #202
Gem versions:
rails-4.2.7.1
sentry-raven-2.6.2
The text was updated successfully, but these errors were encountered: