diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d5b0663f5..63050a999f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,10 @@ Version of the agent adds log-level filtering, adds custom attributes for 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#2092](https://github.com/newrelic/newrelic-ruby-agent/pull/2092). + - **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) diff --git a/lib/new_relic/agent/method_tracer_helpers.rb b/lib/new_relic/agent/method_tracer_helpers.rb index 6fbd212f71..6db3287349 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