From 14550d85af73dfcf528c85f455ea32eec8450f9a Mon Sep 17 00:00:00 2001 From: Tanna McClure Date: Wed, 21 Jun 2023 13:34:32 -0700 Subject: [PATCH 1/6] update code level metrics to work with active record classes --- lib/new_relic/agent/method_tracer_helpers.rb | 6 +++--- .../agent/method_tracer_helpers_test.rb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/new_relic/agent/method_tracer_helpers.rb b/lib/new_relic/agent/method_tracer_helpers.rb index 6fbd212f71..60a215c0d3 100644 --- a/lib/new_relic/agent/method_tracer_helpers.rb +++ b/lib/new_relic/agent/method_tracer_helpers.rb @@ -68,10 +68,10 @@ def clm_enabled? end # The string representation of a singleton class looks like - # '#'. Return the 'MyModule::MyClass' part of - # that string + # '#', or '#' + # Return the 'MyModule::MyClass' part of that string def klass_name(object) - name = Regexp.last_match(1) if object.to_s =~ /^#$/ + name = Regexp.last_match(1) if object.to_s =~ /^#$/ return name if name raise "Unable to glean a class name from string '#{object}'" diff --git a/test/new_relic/agent/method_tracer_helpers_test.rb b/test/new_relic/agent/method_tracer_helpers_test.rb index b11e59a3f3..e25f2044c2 100644 --- a/test/new_relic/agent/method_tracer_helpers_test.rb +++ b/test/new_relic/agent/method_tracer_helpers_test.rb @@ -151,6 +151,23 @@ def test_clm_memoization_hash_uses_frozen_keys_and_values if defined?(::Rails::VERSION::MAJOR) && ::Rails::VERSION::MAJOR >= 7 require_relative '../../environments/rails70/app/controllers/no_method_controller' + module ::The + class ActiveRecordExample < ActiveRecord::Base + def self.class_method; end + def instance_method; end + private # rubocop:disable Layout/EmptyLinesAroundAccessModifier + def private_method; end + end + end + + def test_provides_accurate_name_for_active_record_class + with_config(:'code_level_metrics.enabled' => true) do + klass = NewRelic::Agent::MethodTracerHelpers.send(:klassify_singleton, The::ActiveRecordExample.singleton_class) + + assert_equal klass, The::ActiveRecordExample + end + end + def test_provides_info_for_no_method_on_controller skip_unless_minitest5_or_above From 1a6f3d0fe22b0848dc5a00229df479a8251e529f Mon Sep 17 00:00:00 2001 From: Tanna McClure Date: Wed, 21 Jun 2023 13:40:16 -0700 Subject: [PATCH 2/6] add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21ece27853..cbc1be26e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,10 @@ Version of the agent adds log-level filtering, an API to add custom attrib Controllers in Rails automatically render views with names that correspond to valid routes. This means that a controller method may not have a corresponding method in the controller class. Code-Level Metrics now report on these methods and don't log false warnings. Thanks to [@jcrisp](https://github.com/jcrisp) for reporting this issue. [PR#2061](https://github.com/newrelic/newrelic-ruby-agent/pull/2061) +- **Bugfix: Code-Level Metrics for ActiveRecord models** + + Classes that inherit from ActiveRecord were not reporting Code-Level Metrics due to an error in the agent when identifying the class name. This has been fixed and Code-Level Metrics will now report for ActiveRecord models. Thanks to [@abigail-rolling](https://github.com/abigail-rolling) for reporting this issue. [PR#20](). + - **Bugfix: Private method `clear_tags!` for NewRelic::Agent::Logging::DecoratingFormatter** As part of a refactor included in a previous release of the agent, the method `NewRelic::Agent::Logging::DecoratingFormatter#clear_tags!` was incorrectly made private. This method is now public again. Thanks to [@dark-panda](https://github.com/dark-panda) for reporting this issue. [PR#](https://github.com/newrelic/newrelic-ruby-agent/pull/2078) From a69619bd7dd2576f30dc83eb23a45a9a91deecdb Mon Sep 17 00:00:00 2001 From: Tanna McClure Date: Wed, 21 Jun 2023 13:52:51 -0700 Subject: [PATCH 3/6] add pr link to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc1be26e5..4434966de4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ Version of the agent adds log-level filtering, an API to add custom attrib - **Bugfix: Code-Level Metrics for ActiveRecord models** - Classes that inherit from ActiveRecord were not reporting Code-Level Metrics due to an error in the agent when identifying the class name. This has been fixed and Code-Level Metrics will now report for ActiveRecord models. Thanks to [@abigail-rolling](https://github.com/abigail-rolling) for reporting this issue. [PR#20](). + Classes that inherit from ActiveRecord were not reporting Code-Level Metrics due to an error in the agent when identifying the class name. This has been fixed and Code-Level Metrics will now report for ActiveRecord models. Thanks to [@abigail-rolling](https://github.com/abigail-rolling) for reporting this issue. [PR#2092](https://github.com/newrelic/newrelic-ruby-agent/pull/2092). - **Bugfix: Private method `clear_tags!` for NewRelic::Agent::Logging::DecoratingFormatter** From ba3e57db25cc0b2c01ba3d1a8eef9ec8e5c24d1a Mon Sep 17 00:00:00 2001 From: Tanna McClure Date: Wed, 21 Jun 2023 14:27:26 -0700 Subject: [PATCH 4/6] update regex to be more correct and also not give a warning --- lib/new_relic/agent/method_tracer_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_relic/agent/method_tracer_helpers.rb b/lib/new_relic/agent/method_tracer_helpers.rb index 60a215c0d3..b4357f6c5b 100644 --- a/lib/new_relic/agent/method_tracer_helpers.rb +++ b/lib/new_relic/agent/method_tracer_helpers.rb @@ -71,7 +71,7 @@ def clm_enabled? # '#', or '#' # Return the 'MyModule::MyClass' part of that string def klass_name(object) - name = Regexp.last_match(1) if object.to_s =~ /^#$/ + name = Regexp.last_match(1) if object.to_s =~ /^#$/ return name if name raise "Unable to glean a class name from string '#{object}'" From bce6d4a13d6f1b2620d6360b528dd027e3501fb5 Mon Sep 17 00:00:00 2001 From: Tanna McClure Date: Wed, 21 Jun 2023 15:41:40 -0700 Subject: [PATCH 5/6] Update lib/new_relic/agent/method_tracer_helpers.rb Co-authored-by: James Bunch --- lib/new_relic/agent/method_tracer_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_relic/agent/method_tracer_helpers.rb b/lib/new_relic/agent/method_tracer_helpers.rb index b4357f6c5b..43bba9f7f7 100644 --- a/lib/new_relic/agent/method_tracer_helpers.rb +++ b/lib/new_relic/agent/method_tracer_helpers.rb @@ -68,7 +68,7 @@ def clm_enabled? end # The string representation of a singleton class looks like - # '#', or '#' + # '#', or '#' # Return the 'MyModule::MyClass' part of that string def klass_name(object) name = Regexp.last_match(1) if object.to_s =~ /^#$/ From d97fabea5a61ce22fc0d5636598d25abe151d986 Mon Sep 17 00:00:00 2001 From: Tanna McClure Date: Wed, 21 Jun 2023 15:42:03 -0700 Subject: [PATCH 6/6] Update lib/new_relic/agent/method_tracer_helpers.rb Co-authored-by: James Bunch --- lib/new_relic/agent/method_tracer_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_relic/agent/method_tracer_helpers.rb b/lib/new_relic/agent/method_tracer_helpers.rb index 43bba9f7f7..6db3287349 100644 --- a/lib/new_relic/agent/method_tracer_helpers.rb +++ b/lib/new_relic/agent/method_tracer_helpers.rb @@ -71,7 +71,7 @@ def clm_enabled? # '#', or '#' # Return the 'MyModule::MyClass' part of that string def klass_name(object) - name = Regexp.last_match(1) if object.to_s =~ /^#$/ + name = Regexp.last_match(1) if object.to_s =~ /^#$/ return name if name raise "Unable to glean a class name from string '#{object}'"