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

Custom method tracing for class methods shows error when code_level_metrics are enabled and class overrides inspect method #2064

Closed
arolling-sa opened this issue Jun 9, 2023 · 3 comments · Fixed by #2092
Labels
bug community To tag external issues and PRs submitted by the community

Comments

@arolling-sa
Copy link

Description

Recently when updating newrelic_rpm from version 8.8.0 to 9.2.0 in our Rails 7 project, we encountered errors for all of our custom method traces that were applied to class methods. These were set up in an initializer and had been working for all previous versions.

WARN : Unable to determine source code info for '#<Class:Foo(id: integer, created_at: datetime, updated_at: datetime, name: string)>', method 'drive' - NameError: wrong constant name Foo(id: integer, created_at: datetime, updated_at: datetime, name: string)

        Object.const_get(klass_name(object))
              ^^^^^^^^^^

Expected Behavior

Class methods should support custom method tracing as per the documentation.

Troubleshooting results

After some digging, we determined that what was shown in the logs was the output of the ActiveRecord override of inspect, which was not in the format expected by the klass_name method:

# The string representation of a singleton class looks like
# '#<Class:MyModule::MyClass>'. Return the 'MyModule::MyClass' part of
# that string
def klass_name(object)
name = Regexp.last_match(1) if object.to_s =~ /^#<Class:(.*)>$/
return name if name
raise "Unable to glean a class name from string '#{object}'"
end

This method is only called when code_level_metrics.enabled is true and the default value was changed in the 8.10.0 release, introducing this bug.

Steps to Reproduce

Add custom method tracing to a class method for a class that inherits from ActiveRecord:

Foo.class_eval do
  class << self
    include ::NewRelic::Agent::MethodTracer

    add_method_tracer :drive, "Custom/Foo.drive"
  end
end

Additional context

Class methods for classes that don't inherit from ActiveRecord did not generate any errors or warnings; disabling code_level_metrics eliminated the problem. While this was encountered in a Rails app, we believe it will affect any class that overrides inspect.

For Maintainers Only or Hero Triaging this bug

Suggested Priority (P1,P2,P3,P4,P5):
Suggested T-Shirt size (S, M, L, XL, Unknown):

@arolling-sa arolling-sa added the bug label Jun 9, 2023
@workato-integration
Copy link

@github-actions github-actions bot added the community To tag external issues and PRs submitted by the community label Jun 9, 2023
@tannalynn
Copy link
Contributor

Thank you for bringing this to our attention @abigail-rolling
We'll take a look at this issue and see if we can reproduce this issue and look into preventing this from occurring in the future.

@tannalynn
Copy link
Contributor

A fix for this will be included in our next release, thanks for letting us know about this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug community To tag external issues and PRs submitted by the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants