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: Record code level metric attributes for private methods #1593

Merged
merged 4 commits into from
Nov 8, 2022

Conversation

tannalynn
Copy link
Contributor

Before contributing, please read our contributing guidelines and code of conduct.

Overview

This resolves the error caused by setting add_method_tracer on a private method. Previously, the agent would fail to check the private method as an instance method because it was not included in the instance_methods array, so it attempted to record it as a class method, resulting in the following error in the logs

WARN : Unable to determine source code info for 'Example', method 'private_method' - NameError: undefined method 'private_method' for class '#<Class:Example>'

resolves #1589 Thanks @jdelStrother for the suggested fix!

Submitter Checklist:

  • Include a link to the related GitHub issue, if applicable
  • Include a security review link, if applicable

Testing

The agent includes a suite of unit and functional tests which should be used to
verify your changes don't break existing functionality. These tests will run with
GitHub Actions when a pull request is made. More details on running the tests locally can be found
here for our unit tests,
and here for our functional tests.
For most contributions it is strongly recommended to add additional tests which
exercise your changes.

Reviewer Checklist

  • Perform code review
  • Add performance label
  • Perform appropriate level of performance testing
  • Confirm all checks passed
  • Add version label prior to acceptance

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2022

SimpleCov Report

Coverage Threshold
Line 93.25% 93%
Branch 84.16% 84%

@@ -106,7 +106,7 @@ def namespace_and_location(object, method_name)
klass = object.singleton_class? ? klassify_singleton(object) : object
name = klass.name || '(Anonymous)'
is_class_method = false
method = if klass.instance_methods.include?(method_name)
method = if (klass.instance_methods + klass.private_instance_methods).include?(method_name)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran some microbenchmarking on different ways to combine arrays, and + was the fastest one, but not by much, all but one said same-ish: difference falls within error

@tannalynn tannalynn merged commit 8965914 into dev Nov 8, 2022
@fallwith fallwith deleted the bugfix_code_level_metrics_private_methods branch November 14, 2022 19:01
@jcrisp
Copy link

jcrisp commented Jun 5, 2023

Hi, I am receiving a similar warning
WARN : Unable to determine source code info for 'XYZController', method 'index'.
The controller doesn't have a method for 'index' but it does have an 'index' view and it is in routes.rb. The method is not required on the Controller in this case, and this has always worked in Rails. My newrelic_agent.log is full of this warning. Can this check be fixed or disabled? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Unable to determine source code info" on instrumenting private methods
3 participants