summaryrefslogtreecommitdiff
path: root/lib/gitlab/grape_logging
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-11 15:06:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-11 15:06:42 +0000
commit7071f9bf3e131a7a668922ee450da529f1866b6f (patch)
tree590371b44d47d428f2826b600d7fab4f10520051 /lib/gitlab/grape_logging
parent16bd8409bcb61d2331227d1df539c40683b6bda3 (diff)
downloadgitlab-ce-7071f9bf3e131a7a668922ee450da529f1866b6f.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/grape_logging')
-rw-r--r--lib/gitlab/grape_logging/loggers/exception_logger.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/gitlab/grape_logging/loggers/exception_logger.rb b/lib/gitlab/grape_logging/loggers/exception_logger.rb
new file mode 100644
index 00000000000..022eb15d28d
--- /dev/null
+++ b/lib/gitlab/grape_logging/loggers/exception_logger.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GrapeLogging
+ module Loggers
+ class ExceptionLogger < ::GrapeLogging::Loggers::Base
+ def parameters(request, _)
+ # grape-logging attempts to pass the logger the exception
+ # (https://github.com/aserafin/grape_logging/blob/v1.7.0/lib/grape_logging/middleware/request_logger.rb#L63),
+ # but it appears that the rescue_all in api.rb takes
+ # precedence so the logger never sees it. We need to
+ # store and retrieve the exception from the environment.
+ exception = request.env[::API::Helpers::API_EXCEPTION_ENV]
+
+ return {} unless exception.is_a?(Exception)
+
+ data = {
+ exception: {
+ class: exception.class.to_s,
+ message: exception.message
+ }
+ }
+
+ if exception.backtrace
+ data[:exception][:backtrace] = Gitlab::Profiler.clean_backtrace(exception.backtrace)
+ end
+
+ data
+ end
+ end
+ end
+ end
+end