I'm using spring micrometer for tracing purpose and tried configuring the HttpClient
the following way.
MicrometerHttpClientInterceptor interceptorProvider = new MicrometerHttpClientInterceptor(new SimpleMeterRegistry(),
x -> x.getRequestLine().getUri(),
Tags.empty(),
false);
return HttpClients.custom()
.addInterceptorFirst(interceptorProvider.getRequestInterceptor())
.addInterceptorLast(interceptorProvider.getResponseInterceptor())
.build();
But the http client is not adding tracing headers to any of the HTTP requests.
Is there anything equivalent to Brave's instrumentation or any support for interceptors from Micrometer?
EDITED ANSWER:
After the initial solution, I later figured out the previous solution (below) creates a new observation leading to generation of new spanIds. This is undesired behavior.
Hence I went with the interceptor approach:
Interceptor:
Registering the interceptor while creating client:
tracer and propagator are taken from Spring container by autowiring.
Previous answer:
I was able to instrument http client by building it the following way:
ObservationRegistry
is autowired.There is support for both apache HC4 and HC5. Import accordingly.
I also had missed adding the below properties.