sentry-ruby: Exceptions not sent to Sentry from development environment (better_errors)
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 - https://github.com/getsentry/raven-ruby/issues/202
Gem versions: rails-4.2.7.1 sentry-raven-2.6.2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 18 (4 by maintainers)
Commits related to this issue
- Use middleware instead of method override to handle rescued exceptions There are a few drawbacks on the method override approach: 1. It's hard to properly cleanup the patched method after tests. This... — committed to getsentry/sentry-ruby by st0012 4 years ago
- 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. Thi... — committed to getsentry/sentry-ruby by st0012 4 years ago
- 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. Thi... — committed to getsentry/sentry-ruby by st0012 4 years ago
- Use middleware instead of method override to handle rescued exceptions (#1168) * Allow configuring test app dynamically as well * Group test cases base on prod/dev setup * Use middleware instea... — committed to getsentry/sentry-ruby by st0012 4 years ago
I have same problem and for me it’s caused by
better_errorsgem.Simply add better_errors gem to your script to reproduce.
Raven inserts its middleware,
Raven::Rack, in the first (outermost) position. This is desirable because it catches any exceptions that bubble up, especially those that happen in the middleware stack itself.BetterErrors inserts its middleware,
BetterErrors::Middleware, just afterDebugExceptions, if it is defined. In the PR that put it there, it’s mentioned that this is nice since BetterErrors will render a page for exceptions that originate in all middlewares that are afterDebugExceptions. It must be afterDebugExceptionsitself, however, sinceDebugExceptionswould otherwise swallow the exception before BetterErrors could access it.In order to prevent
DebugExceptionsfrom swallowing the exception, Raven instead patchesActionDispatch::DebugExceptionsandActionDispatch::ShowExceptionsin that way that makes it so that errors are reported to Sentry first before rendering the error page.So, one way to add compatibility for BetterErrors to Raven is to patch
BetterErrors::Middlewarein a similar way that Raven currently does toActionDispatch::DebugExcecptionsandActionDispatch::ShowExceptions.In a Rails initializer,
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.
Hi, I also encountered the same issue. I don’t have better_errors gem in my project.
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.
OK. For info here is our initializer after updating from sentry-raven to sentry-ruby 4.1.1:
Good news: I came up with another way to address these kinds of issue in https://github.com/getsentry/sentry-ruby/pull/1168. The PR should fix this issue and will be included in version
4.1.2ofsentry-rails.However, I won’t backport this fix to the old
sentry-ravenSDK as this is not a critical issue. So I highly recommend you to migrate to the new SDK by following this guideline.