Errors in custom middlewares are not logged or passed to Sentry
In #220561, we saw that the Go middleware (https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/middleware/go.rb) fails in some circumstances.
This was made harder to debug because we only saw the 500s in the Workhorse logs, not in Sentry or the Rails logs. Obviously the Workhorse logs don't contain details about the Rails-side error.
I tested this locally having configured Sentry for my GDK:
diff --git a/lib/gitlab/middleware/go.rb b/lib/gitlab/middleware/go.rb index abdbccd3aa8..d0d62f1da42 100644 --- a/lib/gitlab/middleware/go.rb +++ b/lib/gitlab/middleware/go.rb @@ -16,7 +16,7 @@ module Gitlab def call(env) request = ActionDispatch::Request.new(env) - + raise 'hi' render_go_doc(request) || @app.call(env) end
I see the error when I visit a page:
But it does not show:
- In Sentry: https://sentry.gitlab.net/gitlab/sean-test/
grep RuntimeError log/exceptions_json.logshows nothing).
It does show in
development.log, but that's useless as we don't have the equivalent in production: https://docs.gitlab.com/ee/development/logging.html#dont-use-railslogger
This also happens for other custom middlewares we have, like the Jira middleware.