Module: BrainzLab::Instrumentation::SolidQueueInstrumentation

Defined in:
lib/brainzlab/instrumentation/solid_queue.rb

Class Method Summary collapse

Class Method Details

.around_enqueue(job) ⇒ Object



175
176
177
178
179
180
181
182
183
184
# File 'lib/brainzlab/instrumentation/solid_queue.rb', line 175

def self.around_enqueue(job)
  yield
rescue StandardError => e
  if BrainzLab.configuration.reflex_effectively_enabled?
    BrainzLab::Reflex.capture(e,
                              tags: { job_class: job.class.name, queue: job.queue_name },
                              extra: { job_id: job.job_id, arguments: safe_arguments(job) })
  end
  raise
end

.around_perform(job) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/brainzlab/instrumentation/solid_queue.rb', line 121

def self.around_perform(job)
  job_class = job.class.name
  queue = job.queue_name || 'default'
  started_at = Time.now

  # Set context for the job
  BrainzLab::Context.current.set_context(
    job_class: job_class,
    job_id: job.job_id,
    queue: queue
  )

  begin
    yield
  rescue StandardError => e
    # Capture error with Reflex
    if BrainzLab.configuration.reflex_effectively_enabled?
      BrainzLab::Reflex.capture(e,
                                tags: { job_class: job_class, queue: queue },
                                extra: {
                                  job_id: job.job_id,
                                  arguments: safe_arguments(job),
                                  executions: job.executions
                                })
    end
    raise
  ensure
    duration_ms = ((Time.now - started_at) * 1000).round(2)

    # Record trace
    if BrainzLab.configuration.pulse_effectively_enabled?
      BrainzLab::Pulse.record_trace(
        "job.#{job_class}",
        kind: 'job',
        started_at: started_at,
        ended_at: Time.now,
        job_class: job_class,
        job_id: job.job_id,
        queue: queue,
        executions: job.executions
      )
    end

    # Record metrics
    if BrainzLab.configuration.flux_effectively_enabled?
      tags = { job_class: job_class, queue: queue }
      BrainzLab::Flux.distribution('solid_queue.job.duration_ms', duration_ms, tags: tags)
    end

    # Clear context
    BrainzLab.clear_context!
  end
end

.install!Object



7
8
9
10
11
12
13
14
# File 'lib/brainzlab/instrumentation/solid_queue.rb', line 7

def install!
  return unless defined?(::SolidQueue)

  install_job_instrumentation!
  install_worker_instrumentation!

  BrainzLab.debug_log('[Instrumentation] SolidQueue instrumentation installed')
end

.safe_arguments(job) ⇒ Object



186
187
188
189
190
191
# File 'lib/brainzlab/instrumentation/solid_queue.rb', line 186

def self.safe_arguments(job)
  args = job.arguments
  BrainzLab::Reflex.send(:filter_params, args) if args
rescue StandardError
  '[Unable to serialize]'
end