I've been attempting to set up distributed tracing using Spring Micrometer. To propagate the traceId across various services, it appears necessary to configure our HTTP clients to include this information in the headers.
For the RestTemplate
client, Spring conveniently offers an interceptor that can be set up as shown below:
@Bean
public HttpTracing create(Tracing tracing) {
return HttpTracing
.newBuilder(tracing)
.build();
}
@Bean
public RestTemplate restTemplate(HttpTracing httpTracing) {
return new RestTemplateBuilder()
.interceptors(TracingClientHttpRequestInterceptor.create(httpTracing))
.build();
}
But I couldn't find a similar one for Apache http client. I am not sure if I should write my custom interceptor that does this?
Or is one available already provided by a library.?