Not picking up exceptions within a rack middleware app
jeffblake opened this issue · 4 comments
Description
I have rack-miniprofiler, which is a rack middleware. I was seeing elevated 500 error rates, but no exceptions reported in Bugsnag. Looking at the logs I saw
Can Bugsnag pick up and report these errors?
I noticed that the bugsnag middleware Bugsnag::Rack
gets inserted right around the middle in the stack, after miniprofiler, would that have something to do with it? There's no documentation saying where to put the middleware, just to add it to the Gemfile.
Environment
Rails 6
Heroku
Library versions:
latest 6.12.2
production
We put the middleware after ActionDispatch::DebugExceptions
which is typically responsible for catching exceptions and reporting a 500 error - so theres no point in usually being beyond that because good middlewares really shouldnt generate exceptions there. However it looks like miniprofiler goes as far out on the middleware stack as it can https://github.com/MiniProfiler/rack-mini-profiler/blob/2b01bb6e389ad47f01d80cbcc4ed1e58161ab828/lib/mini_profiler_rails/railtie.rb#L57
Yes I understand, I reported the bug to MiniProfiler and Sam has already fixed it. So in theory this shouldn't happen again, but it would be nice if Bugsnag could pick these up, or at least some documentation in place for DIYing this by inserting the Bugsnag middleware to the top of the stack (if that's supported?). For the time being I have an alert setup to monitor response codes.
We can't because of the DebugExceptions middleware rescues all exceptions and renders a pretty looking 500 page in a default rails app. What we have set up is fairly sensible for default rails apps.
Ahhh, right, that makes sense. All good, I'll just make sure my third-party middleware can't throw exceptions, that's really the fix here
Thanks, closing