Module: Speedshop::Cloudwatch::ActiveJob

Defined in:
lib/speedshop/cloudwatch/active_job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/speedshop/cloudwatch/active_job.rb', line 6

def self.included(base)
  base.around_perform :report_job_metrics
end

Instance Method Details

#report_job_metricsObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/speedshop/cloudwatch/active_job.rb', line 10

def report_job_metrics
  begin
    if enqueued_at
      queue_time = Time.now.to_f - enqueued_at.to_f
      # Drop JobClass to reduce time series cardinality and allow aggregation into StatisticSets per queue
      Reporter.instance.report(metric: :QueueLatency, value: queue_time, dimensions: {QueueName: queue_name}, integration: :active_job)
    end
  rescue => e
    Speedshop::Cloudwatch.log_error("Failed to collect ActiveJob metrics: #{e.message}", e)
  end
  yield
end