Merge branch 'an/api-route-logger' into 'master'
Add route information to lograge structured logging for API logs Closes #50993 See merge request gitlab-org/gitlab-ce!21487
This commit is contained in:
commit
9dd34eac14
3 changed files with 31 additions and 0 deletions
5
changelogs/unreleased/an-api-route-logger.yml
Normal file
5
changelogs/unreleased/an-api-route-logger.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
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
|
||||
|
|
25
lib/gitlab/grape_logging/loggers/route_logger.rb
Normal file
25
lib/gitlab/grape_logging/loggers/route_logger.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue