When processing ClientResponse body, tracing context is missing.
One of many way to reproduce it:
clientResponse.mutate().body(dataBuffer -> dataBuffer.doOnNext(db -> log.info("No tracing here")))
Environment: - Spring Boot 3.1.5 - Spring Framework: 6.0.13 - Project Reactor 3.5.11
Comment From: bclozel
org.springframework.web.reactive.function.client.ClientResponse#mutate
returns a Builder
type which is not reactive. The Flux
given as an argument is merely a transformation function and there is no observation attached in the reactor context there. In my opinion this is working as designed. I'm no sure which observation context you would expect there.
I'm closing this issue for now. If you still think there is a bug, a sample project showing the actual use case and explaining what behavior is expected would be useful.
Comment From: norbson
Sample project https://github.com/norbson/sb-tracing
As You see on below screen, when processing response body stream, tracing is lost.
We wiretap on response body (Flux\<DataBuffer>) for generic logging purpose.
Similarly, we wiretap on request body but there is no problem with tracing.
Comment From: norbson
Even more obvious case with Flux.
Code: https://github.com/norbson/sb-tracing/tree/flux
In this case tracing context is missing also later in the chain, when processing already decoded element.
Comment From: norbson
In summary, I believe that restoring threadLocal failed in these cases.
Comment From: bclozel
I've been having a look and I'm not sure at this stage if this is a bug in Spring Framework, in Reactor or an expected behavior given the decoder setup.
I'm seeing that the context is not being established in the tokens.handle
part of the AbstractJackson2Decoder#decode
. I'll need some more time to pinpoint where the context is "lost" and whether we can do something about it.
Comment From: bclozel
After chatting with the reactor team (thanks a lot @chemicL !), this is actually another instance of #30273. This is a complex issue that was fixed in Reactor 3.6 (see the dedicated reactor announcement blog post).
I've upgraded your sample to Spring Boot 3.2 and it all works fine. This is a major feature in Reactor and will not be backported to previous generations.
I'm closing this issue as a result. Thanks for the report!
Comment From: norbson
Thank you for your time and help! And sorry for incomplete description at first.