Skip to content

Commit 3b8beab

Browse files
Merge pull request #3320 from newrelic/rename_activejob_segment
Rename ActiveJob segments
2 parents 2277f52 + 362f254 commit 3b8beab

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
- **Breaking Change: Remove support for Ruby 2.4 and 2.5**
66
Support for Ruby versions 2.4 and 2.5 has been removed. The new minimum required Ruby version is now 2.6. [PR#3314](https://github.com/newrelic/newrelic-ruby-agent/pull/3314)
77

8+
- **Breaking Change: Rename ActiveJob metrics**
9+
ActiveJob metrics have been updated to include the job's class name for more specific reporting. This is a breaking change and may require updating custom dashboards or alerts. [PR#3320](https://github.com/newrelic/newrelic-ruby-agent/pull/3320)
10+
- Old format: `Ruby/ActiveJob/<QueueName>/<Method>`
11+
- New format: `Ruby/ActiveJob/<ClassName>/<QueueName>/<Method>`
12+
813
- **Breaking Change: Rename `bin/newrelic` command to `bin/newrelic_rpm`**
914
The executable file for the agent's CLI has been renamed from `bin/newrelic` to `bin/newrelic_rpm`. This change resolves a name collision with the standalone New Relic CLI tool. [PR#3323](https://github.com/newrelic/newrelic-ruby-agent/pull/3323)
1015

lib/new_relic/agent/instrumentation/active_job_subscriber.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ def metric_name(name, payload)
2222
job = payload[:job] || payload[:jobs].first
2323

2424
queue = job.queue_name
25+
job_class = job.class.name.include?('::') ? job.class.name[job.class.name.rindex('::') + 2..-1] : job.class.name
2526
method = method_from_name(name)
26-
"Ruby/ActiveJob/#{queue}/#{method}"
27+
"Ruby/ActiveJob/#{job_class}/#{queue}/#{method}"
2728
end
2829

2930
PATTERN = /\A([^\.]+)\.active_job\z/

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,28 @@ def perform(error = nil)
2525
end
2626
end
2727

28+
module MyApp
29+
module Jobs
30+
class EmailNotificationJob < ActiveJob::Base
31+
def perform(error = nil)
32+
# NOOP - testing ActiveJob metric name
33+
end
34+
end
35+
end
36+
end
37+
2838
class ActiveJobSubscriberTest < Minitest::Test
2939
NAME = 'perform.active_job'
3040
ID = 71741
3141
SUBSCRIBER = NewRelic::Agent::Instrumentation::ActiveJobSubscriber.new
3242

3343
def test_segment_naming_with_unknown_method
34-
assert_equal 'Ruby/ActiveJob/default/Unknown',
44+
assert_equal 'Ruby/ActiveJob/TestJob/default/Unknown',
3545
SUBSCRIBER.send(:metric_name, 'indecipherable', {job: TestJob.new})
3646
end
3747

3848
def test_segment_naming_multiple_jobs
39-
assert_equal 'Ruby/ActiveJob/default/Unknown',
49+
assert_equal 'Ruby/ActiveJob/TestJob/default/Unknown',
4050
SUBSCRIBER.send(:metric_name, 'indecipherable', {jobs: [TestJob.new, TestJob.new]})
4151
end
4252

@@ -100,6 +110,17 @@ def test_retry_stopped_active_job
100110
end
101111
end
102112

113+
def test_metric_name_namespacing
114+
job = MyApp::Jobs::EmailNotificationJob.new
115+
in_transaction do |txn|
116+
job.perform_now
117+
segments = txn.segments.select { |s| s.name.start_with?('Ruby/ActiveJob') }
118+
segment = segments.detect { |s| s.name == 'Ruby/ActiveJob/EmailNotificationJob/default/perform' }
119+
120+
assert segment
121+
end
122+
end
123+
103124
private
104125

105126
def validate_transaction(txn, methods = [])
@@ -109,7 +130,7 @@ def validate_transaction(txn, methods = [])
109130
refute_empty segments
110131

111132
methods.each do |method|
112-
segment = segments.detect { |s| s.name == "Ruby/ActiveJob/default/#{method}" }
133+
segment = segments.detect { |s| s.name == "Ruby/ActiveJob/TestJob/default/#{method}" }
113134

114135
assert segment
115136

0 commit comments

Comments
 (0)