2

I have spring boot 3.4+ reactive webflux app

we have been using below config to get prometheus metrics (Spring Boot 2.x)

    private ExchangeFilterFunction metricsWebClientFilterFunction(String name) {
        log.info("Register filter function with name: {}", name);
        return new MetricsWebClientFilterFunction(meterRegistry, new DefaultWebClientExchangeTagsProvider(), name, AutoTimer.ENABLED);
    }

But due to new spring boot version with observability API this is not working anymore,

We have tried using below config

WebClient.builder()
                .observationRegistry(registry)
    

Also tried various NamingConventionConfig classes, @Observable but it doesn't help.

We need metrics populated like below

Correct

http_client_requests_seconds{error="none",status="200",uri="/endpoint/",quantile="0.9"} 0.0

We're getting unknown uri metrics like below

http_server_requests_active_seconds_bucket{exception="none",method="GET",outcome="SUCCESS",status="200",uri="UNKNOWN",le="274.877906944"} 1

2 Answers 2

1

See this comment on GitHub from Brian: https://github.com/spring-projects/spring-framework/issues/30322#issuecomment-1597240920

Sign up to request clarification or add additional context in comments.

Comments

0

Figured out a way to achieve similar metrics with spring boot 3.4+ with below configs

private final ObservationRegistry registry;
public WebClientConfig(ObservationRegistry registry) {
    this.registry = registry;
}
public WebClient webClient(String webClientName, String host) {
    HttpClient httpClient = configureHttpClient();
    return WebClient.builder()
            .baseUrl(host)
            .observationRegistry(registry)
            .observationConvention(new DefaultClientRequestObservationConvention(webClientName))
            .clientConnector(new ReactorClientHttpConnector(httpClient))
            .build();
}

And then in the connector class using below code to call external service where

@Autowired
@Qualifier("{qualifierName}")
private WebClient webClient;

@Value("${endpoint from yaml}")
private String endpoint;

public Mono<TargetType> getReq(Integer reqNumber) {
    return webClient.get()
            .uri(endpoint, reqNumber)
            .retrieve()
            .bodyToFlux(TargetType.class)
            .next()
}

This produces correct metrics with right URI including {reqNumber}, status, method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.