-
Notifications
You must be signed in to change notification settings - Fork 147
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
Using @Trace on a method in a utility class in an instrumentation module does not work #1073
Comments
Targeted for the Jan-Mar quarter |
Moving review of this to the Apr-Jun quarter - no capacity to take this up currently |
Hey @kford-newrelic - Customer Success Manager here. As we're in Q2, is there any update to this issue you can share? Customer is asking. |
@jenerallyErrorFree apologies but we haven't had the capacity to take this up. Unfortunately, no ETA at the moment |
We tested this and determined that The "non-working" example that was cited was the TokenLinkingSubscriber utility class in our own
The The only obvious reason why the token linking would fail in this scenario is if the It's not clear if this ticket is specifically meaning to call out a perceived issued with the |
Hi Jason. Thank you so much for your time and investigation! I really appreciate it since this problem is blocking some of the custom instrumentation we would like to write, and therefore preventing us from adopting newrelic in more of our services. I originally found the problem when writing some custom instrumentation, and I spent a lot of time debugging it. Something must be different when running the newrelic java agent in an application as I have done (which demonstrates the problem), versus running the When I filed the original support case, I provided an example project and a short video and that
The support folks directed me to file an issue here. I should have included the video and project here when I filed this issue for you to review. I will link them below. I would really appreciate it if you could review the full video, and use the project to reproduce the problem as I have done, rather than a separate testcase with different setup. Again, thank you for your time. I really hope we can identify what is causing the behavior I am seeing, so we can rollout newrelic to more of our services. |
Hey @philsttr , thanks for the additional context, it does help to clarify a bit. The project that you linked didn't have any controllers in it but I added the following based on what you were showing in the YT video. Let me know if this is not correct for the repro.
I am able to see some of the things you pointed out in the debugger when running the repro app but I'm not entirely clear on what the impact is that is blocking your custom instrumentation. Here's a trace I see when hitting the Also, what version of the Java agent are you using when debugging? Do you have the same issues with the latest version of the agent? We've had quite a few fixes/improvements around Spring/Reactor/Netty/Token linking instrumentation over the past year or so, so if you haven't tested with a recent agent release it would be worth doing so to see if the issue has been resolved. All of the screenshots in this response are captured while debugging with Java agent version 8.4.0. Even though I can see the things you pointed out when hitting the For instance, these screenshots show the token being linked when Generally speaking, using In the past, we've seen cases where an unexpected thread hop due to the use of |
Oops, I attached the wrong zip. But the controller you mentioned is correct. It's a simple project.
When I recorded the video in November, I was using 7.11.0, which was the latest at the time. I have retested today with 8.4.0. I still see the problem with 8.4.0, but the behavior is slightly different, as I'll describe below... Regarding the breakpoint in That breakpoint will be hit on application startup, where the Resume from the breakpoint, allow the app to finish startup, and then call the
But, this is where things are slightly different for 8.4.0. Specifically, in 8.4.0 you'll also see this log message, due to this change...
It appears the link failure now schedules a reinstrumentation of the A few seconds later, when the If you call the Yay! However, all is not working quite yet. Even though token linking in To demonstrate the problem, change the controller to this:
I expect the custom transaction name and parameter to be set in all cases.
I'm not sure if this behavior is related to the original problem, or something else. To summarize... There is still a bug in 8.4.0 in the initial (lack of) instrumentation of There also appears to be a different problem after the reinstrumentation of I'd like to resolve the first problem before focusing too much on the second problem. |
Another observation I made... When testing our custom instrumentation that uses a I believe there is sufficient evidence to prove that instrumentation of these utility classes is not working properly during application startup. I believe you have seen this evidence for yourself. Specifically:
Additionally, the "fix" I mentioned in this issue description and in the video of calling Since...
... I believe it is critical to fix the problem identified while instrumenting utility classes on startup. (Side note: I'll be unavailable from 31. July until 4. Aug, but I can respond after that.) |
I opened PR #1443 to test a change that explicitly calls As you observed, it has the effect of changing the behavior such that the following is no longer logged, and TokenLinkingSubscriber is no longer being retransformed after calling the
There is a custom build of the agent that you can find here if you want to do any testing with it: https://github.com/newrelic/newrelic-java-agent/actions/runs/5827290767 That said, it does not seem to address the problem that you pointed out with the refactoring of the controller where you are setting the transaction name (i.e.
Out of curiosity, with your custom instrumentation, is it specifically failing due to this issue with |
Thanks @jasonjkeller !
Great! I'll test it next week, and let you know how it goes.
Ok, that might not have been the best test. I'll test our custom instrumentation where I first noticed the problem to confirm the fix.
Our custom instrumentation has a new utility class, with some methods annotated with |
I had some time to do a quick test on the custom build today. It does indeed solve the problem. The util classes in our custom instrumentation work properly now. :) |
Awesome, that's great to hear! I'll go ahead and submit the PR to the team for review so that we can look to get it into an upcoming agent release. |
Going to close out this issue as the PR with the fix has been merged and will be included in the next agent release unless any issues crop up between now and then. #1443 I've also gone ahead and filed another ticket for the issue regarding transaction renaming when using Thanks again for all of your help on this issue @philsttr ! |
Description
According to the README.md for instrumentation modules, an instrumentation module consists of weave classes, utility classes, and SkipIfPresent classes.
The
@Trace
annotation is handled properly on methods in weave classes. Unfortunately, it is not handled properly on methods in utility classes.For example, this usage of
@Trace
on a utility class is not handled. Specifically, the token will not be linked properly here, because the@Trace
is not handled properly.Expected Behavior
I expect
@Trace
to work correctly when placed on a method in a utility class in an instrumentation module.Steps to Reproduce
The easiest way to see the non-working behavior is to:
@Trace
in a utility class of an instrumentation module. For example, hereThis message indicates that the
@Trace(async = true)
annotation is not on the method in the utility class. However it actually IS on the method. This is a symptom of the@Trace
not being handled properly on the method in the utility class.Troubleshooting
I have determined that the problem seems to be related to where AgentPostprocessors handles utility classes.
Specifically here,
tracedWeaveInstrumentationTrackers
is always null, because the post processor'stracedWeaveInstrumentationDetails
map is always empty. It appears that the post processor'ssetTracedWeaveInstrumentationDetails
method is never called, therefore thetracedWeaveInstrumentationDetails
map is always empty.Because
tracedWeaveInstrumentationTrackers
is always null... when theTraceClassVisitor
visits the method annotated with@Trace
in the utility class, theTraceDetails
is always null. Therefore the tracer logic is never injected into the utility class bytecode.To confirm this theory, in a debugger I have explicitly called
AgentPostprocessors.setTracedWeaveInstrumentationDetails
with the return value ofAgentPreprocessor.getTracedWeaveInstrumentationDetails
before the post processor is executed inPackageValidationResult.computeUtilityClassBytes
. After doing so, the tracer logic is injected properly into the utility class bytecode, and the@Trace
functionality works properly.Your Environment
newrelic-java-agent 7.11.0
The text was updated successfully, but these errors were encountered: