-
Notifications
You must be signed in to change notification settings - Fork 896
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
#4056 remove oringin handler when removelast in netty #4123
Conversation
} else if (handler | ||
.getClass() | ||
.getName() | ||
.startsWith("io.opentelemetry.javaagent.instrumentation.netty.")) { | ||
pipeline.removeLast(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what if somebody calls pipeline.addAfter(originalHandler, ...)
? Then we'll remove some random custom handler that has nothing to do with our instrumentation. If we want this method to work correctly we should
- Maintain a two-way association between the
originalHandler
andourHandler
(i.e. putourHandler -> originalHandler
into theContextStore
too) and remove theoriginalHandler
wheneverremoveLast()
removes our handler - Instrument
addAfter()
so that it actually adds the new handler afterourHandler
whenever it's associated to theoriginalHandler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, u r right.Maybe we can instrument addAfter()
to make sure ourhandler
will always be added after the originalHandler
. I'll have a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests (probably ChannelPipelineTest
in netty-4.0
& netty-4.1
modules) that verify this new advice works with general add*()
advices?
isMethod().and(named("removeLast")).and(returns(named("io.netty.channel.ChannelHandler"))), | ||
AbstractNettyChannelPipelineInstrumentation.class.getName() + "$RemoveLastAdvice"); | ||
transformer.applyAdviceToMethod( | ||
isMethod().and(named("addAfter")).and(takesArguments(3)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3-args variant calls the 4-args one, it should be enough to instrument the 4-args one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i got it
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void addAfterHandler( | ||
@Advice.This ChannelPipeline pipeline, | ||
@Advice.Argument(value = 1, readOnly = false) String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add takesArgument(1, String.class)
to the method matcher? In general we aim to enclose all types that we use in advice classes (arguments, return types) in the method matcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, of course
@mateuszrzeszutek thanks! It looked better now. But it seemed the check meet some problem now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks!
I left a minor comment about unit tests, but overall it looks good 👍
channelPipeline.first() == httpHandler | ||
// our handler was also added | ||
channelPipeline.last().getClass() == HttpClientTracingHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 assertions are already present in the then:
section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same applies to the other test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, should I remove then in this pr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
@mateuszrzeszutek you're welcome :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 that's a tricky few LOC, thx @tydhot!
No description provided.