diff options
author | Andrew Newdigate <andrew@gitlab.com> | 2018-09-03 20:03:32 +0300 |
---|---|---|
committer | Andrew Newdigate <andrew@gitlab.com> | 2018-09-05 12:01:26 +0300 |
commit | 189b063ee15d3751fb7b03a0794edfdb60893eb8 (patch) | |
tree | 1485fd4f9684077c219f31a50a676fccd1ad3f25 /lib/gitlab/grape_logging | |
parent | 91003c6ebb764c9cf3fe01a14d6213b26c09dcc8 (diff) |
Add route information to lograge structured logging
Diffstat (limited to 'lib/gitlab/grape_logging')
-rw-r--r-- | lib/gitlab/grape_logging/loggers/route_logger.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/gitlab/grape_logging/loggers/route_logger.rb b/lib/gitlab/grape_logging/loggers/route_logger.rb new file mode 100644 index 00000000000..f3146b4dfd9 --- /dev/null +++ b/lib/gitlab/grape_logging/loggers/route_logger.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# This grape_logging module (https://github.com/aserafin/grape_logging) makes it +# possible to log the details of the action +module Gitlab + module GrapeLogging + module Loggers + class RouteLogger < ::GrapeLogging::Loggers::Base + def parameters(request, _) + endpoint = request.env[Grape::Env::API_ENDPOINT] + route = endpoint&.route&.pattern&.origin + + return {} unless route + + { route: route } + rescue + # endpoint.route calls env[Grape::Env::GRAPE_ROUTING_ARGS][:route_info] + # but env[Grape::Env::GRAPE_ROUTING_ARGS] is nil in the case of a 405 response + # so we're rescuing exceptions and bailing out + {} + end + end + end + end +end |