module Mmtrix::Agent::Instrumentation::ActiveJobHelper

Constants

ADAPTER_REGEX

Public Class Methods

adapter() click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 77
def self.adapter
  clean_adapter_name(::ActiveJob::Base.queue_adapter.name)
end
clean_adapter_name(name) click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 83
def self.clean_adapter_name(name)
  name = "ActiveJob::#{$1}" if ADAPTER_REGEX =~ name
  name
end
enqueue(job, block) click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 31
def self.enqueue(job, block)
  run_in_trace(job, block, :Produce)
end
perform(job, block) click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 35
def self.perform(job, block)
  state = ::Mmtrix::Agent::TransactionState.tl_get

  # Don't nest transactions if we're already in a web transaction.
  # Probably inline processing the job if that happens, so just trace.
  if state.in_web_transaction?
    run_in_trace(job, block, :Consume)
  elsif state.in_background_transaction?
    ::Mmtrix::Agent::Transaction.set_default_transaction_name(
      transaction_name_suffix_for_job(job),
      transaction_category)
    block.call
  else
    run_in_transaction(state, job, block)
  end
end
run_in_trace(job, block, event) click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 52
def self.run_in_trace(job, block, event)
  trace_execution_scoped("MessageBroker/#{adapter}/Queue/#{event}/Named/#{job.queue_name}") do
    block.call
  end
end
run_in_transaction(state, job, block) click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 58
def self.run_in_transaction(state, job, block)
  ::Mmtrix::Agent::Transaction.wrap(state,
                                      transaction_name_for_job(job),
                                      :other,
                                      &block)
end
transaction_category() click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 65
def self.transaction_category
  "OtherTransaction/#{adapter}"
end
transaction_name_for_job(job) click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 73
def self.transaction_name_for_job(job)
  "#{transaction_category}/#{transaction_name_suffix_for_job(job)}"
end
transaction_name_suffix_for_job(job) click to toggle source
# File lib/mmtrix/agent/instrumentation/active_job.rb, line 69
def self.transaction_name_suffix_for_job(job)
  "#{job.class}/execute"
end