Http client metrics in Prometheus endpoint is missing while creating the WebClient Manually.
Below code is able to generate the expected http client metrics as shown below,
@Autowired
WebClient.Builder webClientBuilder;
@GetMapping("client")
public Mono<String> getClientData() {
return webClientBuilder.baseUrl("http://localhost:8080").build().get().retrieve().bodyToMono(String.class);
}
**Prometheus Metrics**
http_client_requests_seconds_count{clientName="localhost",method="GET",metric1="firstmetric",metric2="secondmetric",outcome="CLIENT_ERROR",status="404",uri="/",} 1.0
http_client_requests_seconds_sum{clientName="localhost",method="GET",metric1="firstmetric",metric2="secondmetric",outcome="CLIENT_ERROR",status="404",uri="/",} 0.2275663
While creating the WebClient.Builder manually as shown below, the expected metrics(above shown) are missing from Prometheus endpoint.
@GetMapping("client")
public Mono<String> getClientData() {
return WebClient.builder().baseUrl("http://localhost:8080").build().get().retrieve().bodyToMono(String.class);
}
Is there any solution available to get the metrics without Auto wiring the WebClient or WebClient builder(Have explored about MetricsWebClientFilterFunction, But it seems to be deprecated in recent version of spring boot)?