2020-02-27 16:09:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Lograge
|
|
|
|
module CustomOptions
|
2020-05-11 20:10:11 -04:00
|
|
|
include ::Gitlab::Logging::CloudflareHelper
|
|
|
|
|
2020-02-27 16:09:17 -05:00
|
|
|
LIMITED_ARRAY_SENTINEL = { key: 'truncated', value: '...' }.freeze
|
|
|
|
IGNORE_PARAMS = Set.new(%w(controller action format)).freeze
|
2022-07-18 05:08:30 -04:00
|
|
|
KNOWN_PAYLOAD_PARAMS = [:remote_ip, :user_id, :username, :ua, :queue_duration_s, :response_bytes,
|
2021-10-19 08:12:07 -04:00
|
|
|
:etag_route, :request_urgency, :target_duration_s] + CLOUDFLARE_CUSTOM_HEADERS.values
|
2020-02-27 16:09:17 -05:00
|
|
|
|
|
|
|
def self.call(event)
|
|
|
|
params = event
|
|
|
|
.payload[:params]
|
|
|
|
.each_with_object([]) { |(k, v), array| array << { key: k, value: v } unless IGNORE_PARAMS.include?(k) }
|
|
|
|
payload = {
|
|
|
|
time: Time.now.utc.iso8601(3),
|
2021-10-19 08:12:07 -04:00
|
|
|
params: Gitlab::Utils::LogLimitedArray.log_limited_array(params, sentinel: LIMITED_ARRAY_SENTINEL)
|
2020-02-27 16:09:17 -05:00
|
|
|
}
|
2021-10-19 08:12:07 -04:00
|
|
|
|
2020-05-15 14:07:52 -04:00
|
|
|
payload.merge!(event.payload[:metadata]) if event.payload[:metadata]
|
2021-10-19 08:12:07 -04:00
|
|
|
optional_payload_params = event.payload.slice(*KNOWN_PAYLOAD_PARAMS).compact
|
|
|
|
payload.merge!(optional_payload_params)
|
2020-05-15 14:07:52 -04:00
|
|
|
|
2020-02-27 16:09:17 -05:00
|
|
|
::Gitlab::InstrumentationHelper.add_instrumentation_data(payload)
|
|
|
|
|
2020-06-01 14:08:07 -04:00
|
|
|
payload[Labkit::Correlation::CorrelationId::LOG_KEY] = event.payload[Labkit::Correlation::CorrelationId::LOG_KEY] || Labkit::Correlation::CorrelationId.current_id
|
2020-02-27 16:09:17 -05:00
|
|
|
|
|
|
|
# https://github.com/roidrage/lograge#logging-errors--exceptions
|
|
|
|
exception = event.payload[:exception_object]
|
|
|
|
|
|
|
|
::Gitlab::ExceptionLogFormatter.format!(exception, payload)
|
|
|
|
|
2021-11-22 10:14:13 -05:00
|
|
|
if Feature.enabled?(:feature_flag_state_logs, type: :ops)
|
|
|
|
payload[:feature_flag_states] = Feature.logged_states.map { |key, state| "#{key}:#{state ? 1 : 0}" }
|
|
|
|
end
|
|
|
|
|
2022-07-18 05:08:30 -04:00
|
|
|
if Feature.disabled?(:log_response_length)
|
|
|
|
payload.delete(:response_bytes)
|
|
|
|
end
|
|
|
|
|
2020-02-27 16:09:17 -05:00
|
|
|
payload
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|