Commit 2da8f89e authored by Stan Hu's avatar Stan Hu

Connect Puma low-level error handler to Sentry in puma.rb example

We saw in
https://gitlab.com/gitlab-com/gl-infra/production/-/issues/5194 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. The error
still will get logged on stderr by Puma.

This mirrors the change we're making in CNG and Omnibus:

1. https://gitlab.com/gitlab-org/charts/gitlab/-/issues/2818
2. https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/6284

Testing notes are in
https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/5490.
parent dc6a267a
...@@ -82,3 +82,12 @@ json_formatter = Gitlab::PumaLogging::JSONFormatter.new ...@@ -82,3 +82,12 @@ json_formatter = Gitlab::PumaLogging::JSONFormatter.new
log_formatter do |str| log_formatter do |str|
json_formatter.call(str) json_formatter.call(str)
end end
lowlevel_error_handler do |ex, env|
if Raven.configuration.capture_allowed?
Raven.capture_exception(ex, tags: { 'handler': 'puma_low_level' }, extra: { puma_env: env })
end
# note the below is just a Rack response
[500, {}, ["An error has occurred and reported in the system's low-level error handler."]]
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment