Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for code level metrics on active record classes #2092

Merged
merged 7 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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, attrbiute: string)>'
tannalynn marked this conversation as resolved.
Show resolved Hide resolved
# 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:]*).*>$/
tannalynn marked this conversation as resolved.
Show resolved Hide resolved
fallwith marked this conversation as resolved.
Show resolved Hide resolved
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