Module: Gitlab::ExceptionLogFormatter

Defined in:
lib/gitlab/exception_log_formatter.rb

Class Method Summary collapse

Class Method Details

.format!(exception, payload) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/exception_log_formatter.rb', line 5

def self.format!(exception, payload)
  return unless exception

  # Elasticsearch/Fluentd don't handle nested structures well.
  # Use periods to flatten the fields.
  payload.merge!(
    'exception.class' => exception.class.name,
    'exception.message' => exception.message
  )

  payload.delete('extra.server')

  payload['extra.sidekiq'].tap do |value|
    if value.is_a?(Hash) && value.key?('args')
      value = value.dup
      payload['extra.sidekiq']['args'] = Gitlab::ErrorTracking::Processor::SidekiqProcessor
                                           .loggable_arguments(value['args'], value['class'])
    end
  end

  if exception.backtrace
    payload['exception.backtrace'] = Rails.backtrace_cleaner.clean(exception.backtrace)
  end
end