Module: Appsignal::Hooks::ActiveJobHook::ActiveJobHelpers

Defined in:
lib/appsignal/hooks/active_job.rb

Constant Summary collapse

ACTION_MAILER_CLASSES =
[
  "ActionMailer::DeliveryJob",
  "ActionMailer::Parameterized::DeliveryJob",
  "ActionMailer::MailDeliveryJob"
].freeze

Class Method Summary collapse

Class Method Details

.action_name(job) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/appsignal/hooks/active_job.rb', line 133

def self.action_name(job)
  case job["job_class"]
  when *ACTION_MAILER_CLASSES
    job["arguments"][0..1].join("#")
  else
    "#{job["job_class"]}#perform"
  end
end

.add_distribution_value(key, value, tags = {}) ⇒ Object



192
193
194
# File 'lib/appsignal/hooks/active_job.rb', line 192

def self.add_distribution_value(key, value, tags = {})
  Appsignal.add_distribution_value("active_job_#{key}", value, tags)
end

.increment_counter(key, value, tags = {}) ⇒ Object



188
189
190
# File 'lib/appsignal/hooks/active_job.rb', line 188

def self.increment_counter(key, value, tags = {})
  Appsignal.increment_counter "active_job_#{key}", value, tags
end

.metrics_for(job) ⇒ Array

Returns an array of metrics with tags used to report the job metrics

If job ONLY has a queue, it will return ‘queue_job_count` with tags. If job has a queue AND priority, it will ALSO return `queue_priority_job_count` with tags.

Returns:

  • (Array)

    Array of metrics with tags to report.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/appsignal/hooks/active_job.rb', line 149

def self.metrics_for(job)
  tags = { :queue => job["queue_name"] }
  metrics = [["queue_job_count", tags]]

  priority = job["priority"]
  if priority
    metrics << [
      "queue_priority_job_count",
      tags.merge(:priority => priority)
    ]
  end

  metrics
end

.transaction_tags_for(job) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/appsignal/hooks/active_job.rb', line 164

def self.transaction_tags_for(job)
  tags = {}

  queue = job["queue_name"]
  tags[:queue] = queue if queue

  priority = job["priority"]
  tags[:priority] = priority if priority

  executions = job["executions"]
  tags[:executions] = executions.to_i + 1 if executions

  job_id = job["job_id"]
  tags[:active_job_id] = job_id

  provider_job_id = job["provider_job_id"]
  tags[:provider_job_id] = provider_job_id if provider_job_id

  request_id = provider_job_id || job_id
  tags[:request_id] = request_id if request_id

  tags
end