Module: Gitlab::ExceptionLogFormatter

Defined in:
lib/gitlab/exception_log_formatter.rb

Class Method Summary collapse

Class Method Details

.find_sql(exception) ⇒ Object


25
26
27
28
29
30
31
32
# File 'lib/gitlab/exception_log_formatter.rb', line 25

def find_sql(exception)
  if exception.is_a?(ActiveRecord::StatementInvalid)
    # StatementInvalid may be caused by a statement timeout or a bad query
    normalize_query(exception.sql.to_s)
  elsif exception.cause.present?
    find_sql(exception.cause)
  end
end

.format!(exception, payload) ⇒ Object


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

def 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' => sanitize_message(exception)
  )

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

  if sql = find_sql(exception)
    payload['exception.sql'] = sql
  end
end