Original install method (e.g. download page, yum, deb, from source, etc.) and version: Download page
Fresh install or upgraded from other version?: Fresh
Is there anything special in your setup? No
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
Im trying to tag external http requests made with webclient. Based on this issue, im trying to use a webclient filter to get the current span and add a tag, but the current span I get is the parent one, not the external request span.
Looks like the external span is not started when the filter is executed, the filter executes before this method.
I believe the span should be started before in the call stack to allow this customization, here perhaps.
Hi @mrodal,
Could you please share a snippet of how you use the spring webclient?
Unfortunately the reactive nature of the webclient makes it very hard to propagate the context to every possible location.
I tried locally, the span should be available within the lambda passed to the exchange methods:
client.get().uri(uri).exchangeToFlux(response -> {
Span span = ElasticApm.currentSpan(); //should be the correct span here
return response.bodyToFlux(String.class);
}
)
.blockLast();
Hi @Jonas_Kunz ,
The idea wat to apply a similar approach to the interceptors with restTemplate (which work as expected) using webclient filter functions to apply the span transformations to all subsequent requests.
I had not tried your approach getting the span on the exchange function, it would require to add the label on each request, but it could work as last resort. The issue is that I also get the parent transaction there, heres my code:
Why does this work? Our webclient instrumentation targets classes implementing the spring ExchangeFunction interface which also have ExchangeFunction in their name. This means in the code above the span is already started within SpanAwareExchangeFunction and therefore is accessible to you. It is important that SpanAwareExchangeFunction is not a lambda, so that the name contains "ExchangeFunction", because otherwise it will not be instrumented.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.