Issue 614 spring webclient tracing#831
Conversation
tylerbenson
left a comment
There was a problem hiding this comment.
This is awesome. Thanks for taking this on. Please see feedback below.
Also, could you add some tests? You can use HttpClientTest as a base (for example), but feel free to add additional tests that might be unique to webflux.
Also, what was your concern about licensing?
Good work!
There was a problem hiding this comment.
This check is not really needed... we added it to okhttp client because we use that internally to report traces to the agent.
There was a problem hiding this comment.
The check for the header is needed because otherwise the advice over and over again and results in a stackoverflow.
It's not very clean so any suggestions for a more subtle solution are more than welcome.
There was a problem hiding this comment.
Perhaps you could explain why it's called over and over again? (Maybe in a comment would be good if we can't figure out a better alternative.) I'm afraid I don't really understand the issue.
There was a problem hiding this comment.
This advice returns a TracingClientResponseMono which is a decorator around the Mono that is returned from the original ExchangeFunction.exchange().
The TracingClientResponseMono class itself also calls ExchangeFunction.exchange() which triggers this advice again.
If the advice is applied the first time, the x-datadog-trace-id header is added to the client request.
If the advice is applied a second time (checked by looking at the x-datadog-trace-id header on the ClientRequest), it won't decorate the result again otherwise this would lead to a StackOverflowError.
Hope this clarifies the issue. If you have a better solution, please share.
...java/datadog/trace/instrumentation/springwebflux/client/DefaultWebClientInstrumentation.java
Outdated
Show resolved
Hide resolved
...java/datadog/trace/instrumentation/springwebflux/client/DefaultWebClientInstrumentation.java
Outdated
Show resolved
Hide resolved
...src/main/java8/datadog/trace/instrumentation/springwebflux/client/ClientResponseWrapper.java
Outdated
Show resolved
Hide resolved
...src/main/java8/datadog/trace/instrumentation/springwebflux/client/ClientResponseWrapper.java
Outdated
Show resolved
Hide resolved
...ava8/datadog/trace/instrumentation/springwebflux/client/TracingClientResponseSubscriber.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
just out of curiosity, under what scenarios would this be called more than once?
There was a problem hiding this comment.
onNext had to be implemented because it's part of the interface of CoreSubscriber.
Could this be called more than once in case of an TEXT_EVENT_STREAM?
...ava8/datadog/trace/instrumentation/springwebflux/client/TracingClientResponseSubscriber.java
Outdated
Show resolved
Hide resolved
...ava8/datadog/trace/instrumentation/springwebflux/client/TracingClientResponseSubscriber.java
Outdated
Show resolved
Hide resolved
...main/java8/datadog/trace/instrumentation/springwebflux/client/TracingClientResponseMono.java
Outdated
Show resolved
Hide resolved
|
@tylerbenson I've added About the licensing: I've copied some code from Opentracing Spring Web but I don't know if all conditions are met (License and copyright notice, State changes) and I'm not that familiar with licensing. |
...java/datadog/trace/instrumentation/springwebflux/client/DefaultWebClientInstrumentation.java
Outdated
Show resolved
Hide resolved
...src/main/java8/datadog/trace/instrumentation/springwebflux/client/ClientResponseWrapper.java
Outdated
Show resolved
Hide resolved
tylerbenson
left a comment
There was a problem hiding this comment.
A few minor requests, and some suggestions on how to work with the tests.
Nice work. I think we're almost done here.
There was a problem hiding this comment.
This method is no longer used.
There was a problem hiding this comment.
Perhaps you could explain why it's called over and over again? (Maybe in a comment would be good if we can't figure out a better alternative.) I'm afraid I don't really understand the issue.
There was a problem hiding this comment.
Ok, this might be a bit messy, but try adding a setupSpec that disables the netty instrumentation via system property (and maybe retransforms the relevant classes?) and an cleanupSpec that does the opposite (so as to not impact the other tests).
Another idea is to possibly override the clientSpan method, but I'm not positive that would work since it's not abstract.
Other ideas?
Last resort, I guess you could just copy the whole test and I can clean it up later.
|
Do you think you'll be able to make these last few changes, or should I try implementing them? |
|
I've been rather busy the past week. Will pick this up tomorrow. |
|
@johanvandeweerd @labbati I decided to try my suggestion (about overriding the |
|
That work has been merged into master (#860). You can follow what I did for the OkHttpClientTest. |
3275ba7 to
27a0749
Compare
|
I looked into this a bit and there seems to be an issue with the netty client span not being linked to the parent span correctly. I'm not exactly sure where it's breaking, but my guess is in the async reactor call. I don't know if it will help, but here's an example of how I instrumented rxjava in hystrix: https://github.com/DataDog/dd-trace-java/blob/master/dd-java-agent/instrumentation/hystrix-1.4/src/main/java/datadog/trace/instrumentation/hystrix/HystrixInstrumentation.java#L99 Let us know if there's anything else we can help with. |
|
@johanvandeweerd I think I have a fix for this, but it will depend on #917 and #886. Can you give me push access to your repo and I can finish updating this? |
27a0749 to
b348f51
Compare
Done. And sorry for the lack of effort lately. |
… and SpringWebfluxHttpClientDecorator
…unctions$DefaultExchangeFunction
…e in spring-webflux-5.0
b348f51 to
aaba3fc
Compare
tylerbenson
left a comment
There was a problem hiding this comment.
@johanvandeweerd want to take a look at my changes to make sure I didn't miss anything?
I'd also like a second review from @labbati @mar-kolya or @randomanderson, but looks good to me now.
randomanderson
left a comment
There was a problem hiding this comment.
Looks good. The only slightly weird thing is that the advice needs to prevent an infinite loop and I see that was already discussed.
I wasn't sure stylistically about saving Tracer to a field vs using GlobalTracer.get() everywhere but I checked and it's not uncommon.
|
@tylerbenson I've locally build the dd-java-agent and tested in a small demo application. Everything looks good! |
|
@johanvandeweerd Thanks to you too for getting it started. You did most of the work. It will be included in the next release, likely this week or next. |
Enabled tracing for Spring WebClient.
Heavily inspired on Opentracing Spring Web.
TODO:
(-) Rework check to only apply the advice once in DefaultWebClientAdvice.java
(-) Licensing