Skip to content

Connect Puma low-level error handler to Sentry

Stan Hu requested to merge sh-add-puma-low-level-handler-sentry into master

We saw in gitlab-com/gl-infra/production#5194 (closed) that errors in a middleware would only be caught by Puma's low-level handler. This error only showed up in the Puma stderr log, which made it difficult to diagnose.

If Sentry is configured, we send the exception to Sentry via Puma's low-level error handler (https://github.com/puma/puma#error-handling). The error still will get logged on stderr by Puma.

Closes #6284 (closed)

Testing

The easiest way to force an error is to return a string in the third (body) argument in /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/middleware/multipart.rb:

diff --git a/lib/gitlab/middleware/multipart.rb b/lib/gitlab/middleware/multipart.rb
index 30b3fe3d8931..ca9dde8dfe7f 100644
--- a/lib/gitlab/middleware/multipart.rb
+++ b/lib/gitlab/middleware/multipart.rb
@@ -168,6 +168,8 @@ def initialize(app)
       end

       def call(env)
+        return [400, { 'Content-Type' => 'text/plain' }, 'hi']
+
         encoded_message = env.delete(RACK_ENV_KEY)
         return @app.call(env) if encoded_message.blank?

Screenshot from https://sentry.gitlab.net/gitlab/gitlab-geo-internal-develop-is/issues/2736918:

image

Edited by Stan Hu

Merge request reports