Commit 189b063e authored by Andrew Newdigate's avatar Andrew Newdigate

Add route information to lograge structured logging

parent 91003c6e
---
title: Add route information to lograge structured logging for API logs
merge_request: 21487
author:
type: other
......@@ -15,6 +15,7 @@ module API
include: [
GrapeLogging::Loggers::FilterParameters.new,
GrapeLogging::Loggers::ClientEnv.new,
Gitlab::GrapeLogging::Loggers::RouteLogger.new,
Gitlab::GrapeLogging::Loggers::UserLogger.new,
Gitlab::GrapeLogging::Loggers::QueueDurationLogger.new,
Gitlab::GrapeLogging::Loggers::PerfLogger.new
......
# 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
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