From 07cfb689379f4ea0971e4a4fc19ee2e78d195640 Mon Sep 17 00:00:00 2001 From: Dylan Griffith Date: Wed, 22 Oct 2025 10:10:13 +0000 Subject: [PATCH] Track exceptions first in api helpers in case we raise again As discussed [in Slack (internal)](https://gitlab.slack.com/archives/C09MZ4NFULC/p1761127646784969?thread_ts=1761127056.018149&cid=C09MZ4NFULC) this code is problematic because we often re-raise when calling `current_user` and this means we lose our original exception. Related to https://gitlab.com/gitlab-org/gitlab/-/issues/429740 So we may be missing the real exception in the logs. --- lib/api/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 630deb64de6a4e..5c45e8e3d629fd 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -661,8 +661,8 @@ def set_status_code_in_env(status) def handle_api_exception(exception) if report_exception?(exception) define_params_for_grape_middleware - Gitlab::ApplicationContext.push(user: current_user, remote_ip: request.ip) Gitlab::ErrorTracking.track_exception(exception) + Gitlab::ApplicationContext.push(user: current_user, remote_ip: request.ip) end # This is used with GrapeLogging::Loggers::ExceptionLogger -- GitLab