Skip to content

Commit

Permalink
Merge pull request #2092 from newrelic/2064_code_level_metrics_active…
Browse files Browse the repository at this point in the history
…_record_models

Bugfix for code level metrics on active record classes
  • Loading branch information
tannalynn authored Jun 23, 2023
2 parents ee94fd5 + d97fabe commit 27311f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Version <dev> 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)
Expand Down
6 changes: 3 additions & 3 deletions lib/new_relic/agent/method_tracer_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def clm_enabled?
end

# The string representation of a singleton class looks like
# '#<Class:MyModule::MyClass>'. Return the 'MyModule::MyClass' part of
# that string
# '#<Class:MyModule::MyClass>', or '#<Class:MyModule::MyClass(id: integer, attribute: string)>'
# Return the 'MyModule::MyClass' part of that string
def klass_name(object)
name = Regexp.last_match(1) if object.to_s =~ /^#<Class:(.*)>$/
name = Regexp.last_match(1) if object.to_s =~ /^#<Class:([\w:]+).*>$/
return name if name

raise "Unable to glean a class name from string '#{object}'"
Expand Down
17 changes: 17 additions & 0 deletions test/new_relic/agent/method_tracer_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 27311f6

Please sign in to comment.