Module: NewRelic::Agent::Instrumentation::ActiveJobHelper
- Includes:
- MethodTracer
- Defined in:
- lib/new_relic/agent/instrumentation/active_job.rb
Constant Summary
collapse
- ADAPTER_REGEX =
/ActiveJob::QueueAdapters::(.*)Adapter/
MethodTracer::ClassMethods::AddMethodTracer::ALLOWED_KEYS, MethodTracer::ClassMethods::AddMethodTracer::DEFAULT_SETTINGS
Class Method Summary
collapse
extended, included, #trace_execution_scoped, #trace_execution_unscoped
#add_method_tracer, #remove_method_tracer
#_nr_clear_traced_methods!, #_nr_default_metric_name, #_nr_derived_class_name, #_nr_traced_method_module, #_nr_validate_method_tracer_options, #method_traced?, #newrelic_method_exists?
Class Method Details
.adapter ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 103
def self.adapter
adapter_class = if ::ActiveJob::Base.queue_adapter.class == Class
::ActiveJob::Base.queue_adapter
else
::ActiveJob::Base.queue_adapter.class
end
clean_adapter_name(adapter_class.name)
end
|
.clean_adapter_name(name) ⇒ Object
115
116
117
118
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 115
def self.clean_adapter_name(name)
name = "ActiveJob::#{$1}" if ADAPTER_REGEX =~ name
name
end
|
.enqueue(job, block) ⇒ Object
50
51
52
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 50
def self.enqueue(job, block)
run_in_trace(job, block, :Produce)
end
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 54
def self.perform(job, block)
state = ::NewRelic::Agent::Tracer.state
txn = state.current_transaction
if txn&.recording_web_transaction?
run_in_trace(job, block, :Consume)
elsif txn && !txn.recording_web_transaction?
::NewRelic::Agent::Transaction.set_default_transaction_name(
transaction_name_suffix_for_job(job),
transaction_category
)
block.call
else
run_in_transaction(job, block)
end
end
|
.run_in_trace(job, block, event) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 73
def self.run_in_trace(job, block, event)
trace_execution_scoped("ActiveJob/#{adapter.sub(/^ActiveJob::/, '')}/Queue/#{event}/Named/#{job.queue_name}",
code_information: code_information_for_job(job)) do
block.call
end
end
|
.run_in_transaction(job, block) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 80
def self.run_in_transaction(job, block)
options = code_information_for_job(job)
options = {} if options.frozen? ::NewRelic::Agent::Tracer.in_transaction(name: transaction_name_for_job(job),
category: :other, options: options, &block)
end
|
.transaction_category ⇒ Object
91
92
93
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 91
def self.transaction_category
"OtherTransaction/#{adapter}"
end
|
.transaction_name_for_job(job) ⇒ Object
99
100
101
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 99
def self.transaction_name_for_job(job)
"#{transaction_category}/#{transaction_name_suffix_for_job(job)}"
end
|
.transaction_name_suffix_for_job(job) ⇒ Object
95
96
97
|
# File 'lib/new_relic/agent/instrumentation/active_job.rb', line 95
def self.transaction_name_suffix_for_job(job)
"#{job.class}/execute"
end
|