Class: Gitlab::ErrorTracking::Processor::SidekiqProcessor

Inherits:
Raven::Processor
  • Object
show all
Defined in:
lib/gitlab/error_tracking/processor/sidekiq_processor.rb

Constant Summary collapse

FILTERED_STRING =
'[FILTERED]'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.filter_arguments(args, klass) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/error_tracking/processor/sidekiq_processor.rb', line 11

def self.filter_arguments(args, klass)
  args.lazy.with_index.map do |arg, i|
    case arg
    when Numeric
      arg
    else
      if permitted_arguments_for_worker(klass).include?(i)
        arg
      else
        FILTERED_STRING
      end
    end
  end
end

.loggable_arguments(args, klass) ⇒ Object


36
37
38
39
40
41
# File 'lib/gitlab/error_tracking/processor/sidekiq_processor.rb', line 36

def self.loggable_arguments(args, klass)
  Gitlab::Utils::LogLimitedArray
    .log_limited_array(filter_arguments(args, klass))
    .map(&:to_s)
    .to_a
end

.permitted_arguments_for_worker(klass) ⇒ Object


26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/error_tracking/processor/sidekiq_processor.rb', line 26

def self.permitted_arguments_for_worker(klass)
  @permitted_arguments_for_worker ||= {}
  @permitted_arguments_for_worker[klass] ||=
    begin
      klass.constantize&.loggable_arguments&.to_set
    rescue
      Set.new
    end
end

Instance Method Details

#process(value, key = nil) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gitlab/error_tracking/processor/sidekiq_processor.rb', line 43

def process(value, key = nil)
  sidekiq = value.dig(:extra, :sidekiq)

  return value unless sidekiq

  sidekiq = sidekiq.deep_dup
  sidekiq.delete(:jobstr)

  # 'args' in this hash => from Gitlab::ErrorTracking.track_*
  # 'args' in :job => from default error handler
  job_holder = sidekiq.key?('args') ? sidekiq : sidekiq[:job]

  if job_holder['args']
    job_holder['args'] = self.class.filter_arguments(job_holder['args'], job_holder['class']).to_a
  end

  value[:extra][:sidekiq] = sidekiq

  value
end