39c1731a53
The Correlation ID is taken or generated from received X-Request-ID. Then it is being passed to all executed services (sidekiq workers or gitaly calls). The Correlation ID is logged in all structured logs as `correlation_id`.
37 lines
1.3 KiB
Ruby
37 lines
1.3 KiB
Ruby
# Only use Lograge for Rails
|
|
unless Sidekiq.server?
|
|
filename = File.join(Rails.root, 'log', "#{Rails.env}_json.log")
|
|
|
|
Rails.application.configure do
|
|
config.lograge.enabled = true
|
|
# Store the lograge JSON files in a separate file
|
|
config.lograge.keep_original_rails_log = true
|
|
# Don't use the Logstash formatter since this requires logstash-event, an
|
|
# unmaintained gem that monkey patches `Time`
|
|
config.lograge.formatter = Lograge::Formatters::Json.new
|
|
config.lograge.logger = ActiveSupport::Logger.new(filename)
|
|
# Add request parameters to log output
|
|
config.lograge.custom_options = lambda do |event|
|
|
params = event.payload[:params]
|
|
.except(*%w(controller action format))
|
|
.each_pair
|
|
.map { |k, v| { key: k, value: v } }
|
|
|
|
payload = {
|
|
time: event.time.utc.iso8601(3),
|
|
params: params,
|
|
remote_ip: event.payload[:remote_ip],
|
|
user_id: event.payload[:user_id],
|
|
username: event.payload[:username],
|
|
ua: event.payload[:ua]
|
|
}
|
|
|
|
gitaly_calls = Gitlab::GitalyClient.get_request_count
|
|
payload[:gitaly_calls] = gitaly_calls if gitaly_calls > 0
|
|
payload[:response] = event.payload[:response] if event.payload[:response]
|
|
payload[Gitlab::CorrelationId::LOG_KEY] = Gitlab::CorrelationId.current_id
|
|
|
|
payload
|
|
end
|
|
end
|
|
end
|