5

I have a spring boot 2.2.2 microservices, which integrations with other services using WebClient (rective). According to Spring documentation, the actuator should return "http.client.requests" metrics by default as Timer is enabled by default. But it does not work for me. I am able to get http.server.requests" metrics.

My WebClient is a bean configured and build with WebClient.builder(), as documented here: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-http-clients

Minghui Liu
  • 51
  • 1
  • 2

2 Answers2

6

Use Spring Boot's preconfigured WebClient.Builder instead of WebClient.builder() to have an instance of WebClient.

You can find more detail here.

As in the following you can have a bean of WebClient.

@Configuration
public class ClientConfiguration {

    @Bean
    public WebClient webClient(WebClient.Builder webClientBuilder) {
        return webClientBuilder
                .baseUrl("https://example.org")
                .build();
    }
}

WebClient.Builder is an Auto-configuration, means the injected point above will receive a newly cloned instance of the builder.

Here is the source for WebClientAutoConfiguration

wpnpeiris
  • 766
  • 4
  • 14
  • When I startup the application, my `ClientConfiguration` always init before `WebClientAutoConfiguration`, that causes Metric Config not work. – Chris Apr 08 '20 at 10:42
1

I've noticed my application has to make a WebClient call before the metrics/http.client.requests endpoint exists. Prior to my application making a WebClient call that endpoint isn't discoverable and returns NOT FOUND.

Hope that helps others in a similar situation!

mrgrew
  • 211
  • 2
  • 8