Skip to content

Commit bb90edd

Browse files
Merge pull request #3110 from tan-linx/dev
Fixes NoMethodError: undefined method `queue_name' for nil in ActiveJobSubscriber when using perform_all_later.
2 parents cbc7a46 + fb4e341 commit bb90edd

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/new_relic/agent/instrumentation/active_job_subscriber.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ module NewRelic
88
module Agent
99
module Instrumentation
1010
class ActiveJobSubscriber < NotificationsSubscriber
11-
PAYLOAD_KEYS = %i[adapter db_runtime error job wait]
11+
PAYLOAD_KEYS = %i[adapter db_runtime error job wait jobs]
1212

1313
def add_segment_params(segment, payload)
1414
PAYLOAD_KEYS.each do |key|
1515
segment.params[key] = payload[key] if payload.key?(key)
1616
end
1717
end
1818

19+
# NOTE: For `enqueue_all.active_job`, only the first job is used to determine the queue.
20+
# Therefore, this assumes all jobs given as arguments for perform_all_later share the same queue.
1921
def metric_name(name, payload)
20-
queue = payload[:job].queue_name
22+
job = payload[:job] || payload[:jobs].first
23+
24+
queue = job.queue_name
2125
method = method_from_name(name)
2226
"Ruby/ActiveJob/#{queue}/#{method}"
2327
end

test/new_relic/agent/instrumentation/rails/active_job_subscriber.rb

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def test_segment_naming_with_unknown_method
3535
SUBSCRIBER.send(:metric_name, 'indecipherable', {job: TestJob.new})
3636
end
3737

38+
def test_segment_naming_multiple_jobs
39+
assert_equal 'Ruby/ActiveJob/default/Unknown',
40+
SUBSCRIBER.send(:metric_name, 'indecipherable', {jobs: [TestJob.new, TestJob.new]})
41+
end
42+
3843
# perform.active_job
3944
def test_perform_active_job
4045
job = TestJob.new

0 commit comments

Comments
 (0)