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)?
The preferred way of getting instrumentation right is to indeed use the WebClient.Builder
instance provided by Spring Boot.
If you don't want that (as a separate question, maybe explain why that choice, maybe there's a way to work around a problem that made you consider that choice), you should in fact wire manually the MetricsWebClientFilterFunction
in the client.
I'm not seeing any deprecation notice on that class, did I miss anything?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.