Welcome to mirror list, hosted at ThFree Co, Russian Federation.

log_formatter.rb « error_tracking « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d004c4e20bbcce8dc6284d73502a311320dd5626 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

module Gitlab
  module ErrorTracking
    class LogFormatter
      # Note: all the accesses to Raven's contexts here are to keep the
      # backward-compatibility to Sentry's built-in integrations. In future,
      # they can be removed.
      def generate_log(exception, context_payload)
        payload = {}

        Gitlab::ExceptionLogFormatter.format!(exception, payload)
        append_user_to_log!(payload, context_payload)
        append_tags_to_log!(payload, context_payload)
        append_extra_to_log!(payload, context_payload)

        payload
      end

      private

      def append_user_to_log!(payload, context_payload)
        user_context = Raven.context.user.merge(context_payload[:user])
        user_context.each do |key, value|
          payload["user.#{key}"] = value
        end
      end

      def append_tags_to_log!(payload, context_payload)
        tags_context = Raven.context.tags.merge(context_payload[:tags])
        tags_context.each do |key, value|
          payload["tags.#{key}"] = value
        end
      end

      def append_extra_to_log!(payload, context_payload)
        extra = Raven.context.extra.merge(context_payload[:extra])
        extra = extra.except(:server)

        # The extra value for sidekiq is a hash whose keys are strings.
        if extra[:sidekiq].is_a?(Hash) && extra[:sidekiq].key?('args')
          sidekiq_extra = extra.delete(:sidekiq)
          sidekiq_extra['args'] = Gitlab::ErrorTracking::Processor::SidekiqProcessor.loggable_arguments(
            sidekiq_extra['args'], sidekiq_extra['class']
          )
          payload["extra.sidekiq"] = sidekiq_extra
        end

        extra.each do |key, value|
          payload["extra.#{key}"] = value
        end
      end
    end
  end
end