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

undefined method `category' for NewRelic::Agent::Transaction:Class #1583

Closed
tatzsuzuki opened this issue Nov 1, 2022 · 3 comments · Fixed by #1587
Closed

undefined method `category' for NewRelic::Agent::Transaction:Class #1583

tatzsuzuki opened this issue Nov 1, 2022 · 3 comments · Fixed by #1587
Labels
bug community To tag external issues and PRs submitted by the community P4-Bug Priority 4 Bug

Comments

@tatzsuzuki
Copy link

tatzsuzuki commented Nov 1, 2022

Description

I get undefined method category for NewRelic::Agent::Transaction::Class when I used it in a piece of code to test out how NewRelic::Agent::Tracer.in_transaction works in my local environment. I also test the same snippet of code in my test environment but couldn't find the information I set (e.g. partial_name) on any page of NewRelic online. I'm not sure those two are related. All other logs and errors have been shown without any problems.

NewRelic::Agent::Tracer.in_transaction(partial_name: 'NR_NAME') do
  Rails.logger.info('NR_INFO')  # I found this is logged
end

When the ruby interpreter reaches the line raises the error, txn is a class but category is defined as an instance attribute.

    239: def self.prefix_for_category(txn, category = nil)
 => 240:   category ||= (txn && txn.category)
    241:   case category
    242:   when :controller then ::NewRelic::Agent::Transaction::CONTROLLER_PREFIX
    ...
    254:   else "#{category.to_s}/" # for internal use only
    255:   end
    256: end

[1] pry(#<Class>)> txn.category
NoMethodError: undefined method `category' for NewRelic::Agent::Transaction:Class
from (pry):7:in `prefix_for_category'

Expected Behavior

partial_name set is recorded and displayed in NR.

Steps to Reproduce

Put the snippet of code I presented above anywhere you want. In my case, I put them in a Rails controller and a worker triggered by Amazon SQS.

Your Environment

Include as many relevant details about your environment as possible including the running version of the Ruby agent, the Ruby version being used and any other relevant environment information

  • ruby v2.7.5p203
  • NewRelic Ruby Agent v8.7.0 - v8.11.0
  • OS Debian GNU/Linux 10 (buster)

Additional context

none

For Maintainers Only or Hero Triaging this bug

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

@tatzsuzuki tatzsuzuki added the bug label Nov 1, 2022
@workato-integration
Copy link

@github-actions github-actions bot added the community To tag external issues and PRs submitted by the community label Nov 1, 2022
@tannalynn
Copy link
Contributor

Hello @tatzsuzuki, thank you for bringing this to our attention.
When the agent dropped support for Ruby 2.0, we updated our api methods to use the built in required keyword arguments feature and removed ArgumentErrors we raised when that argument was missing. Unfortunately it looks like the NewRelic::Agent::Tracer.in_transaction was updated to remove the ArgumentError we would raise if category was not provided, but didn't actually update the method args to identify category as required. This results in this error being logged in the agent logs instead of being helpful and saying . I've made a pull request #1587 to resolve that and make sure category is being treated as a required kwarg.
Since that is the case, you do need to pass in a category kwarg as well as partial_name in order to use the in_transaction method. Adding this argument will resolve this error, and also prevent any ArgumentErrors from being raise in future versions where this is fixed. Hopefully that helps, let me know if there is anything else I can do!

@tannalynn tannalynn added the P4-Bug Priority 4 Bug label Nov 2, 2022
@tatzsuzuki
Copy link
Author

I will try out the method with category. Thank you very much for handling 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 P4-Bug Priority 4 Bug
Projects
Archived in project
2 participants