I have just spent some hours debugging why RestTemplate is not propagating traces to Eureka Server. Turns out RestTemplateTransportClientFactory creates a RestTemplate instance by calling new RestTemplate().
To fix this, RestTemplate.Builder should be used to create a RestTemplate in RestTemplateTransportClientFactory and we get observability support for free.
Now consider the WebFluxWebClient equivalent
public WebClientTransportClientFactories webClientTransportClientFactories(
ObjectProvider<WebClient.Builder> builder) {
return new WebClientTransportClientFactories(builder::getIfAvailable);
}
Here, as expected, the WebClient.Builder is used, and produced TransportClientFactory has observability support ...
Describe the bug
I have just spent some hours debugging why
RestTemplate
is not propagating traces to Eureka Server. Turns outRestTemplateTransportClientFactory
creates aRestTemplate
instance by callingnew RestTemplate()
.To fix this,
RestTemplate.Builder
should be used to create aRestTemplate
inRestTemplateTransportClientFactory
and we get observability support for free.Now consider the WebFlux
WebClient
equivalentHere, as expected, the WebClient.Builder is used, and produced TransportClientFactory has observability support ...
Version: Spring Cloud Starter 2023.0.0