I'm currently working on a Spring webflux project that has Actuator, Micrometer dependencies as follows,
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
to expose default metrics (that include Spring webClient metrics). I'm having 4 different endpoints that I call using the Spring WebClient. I was wondering if there was a way to add specific tags to each of those webclient calls that get added to the default metrics. I have some metrics like Histogram from Webclient exposed at /actuator/prometheus endpoint as follows,
http_client_requests_seconds_bucket{clientName="my-app.com",method="GET",outcome="SUCCESS",status="200",uri="/shops",le="0.001048576",} 0.0
http_client_requests_seconds_bucket{clientName="my-app.com",method="GET",outcome="SUCCESS",status="200",uri="/shops",le="0.002088576",} 1.0
In my code I would like to add few extra tags in the Webclient call that I want for all the metrics above. For example something like this,
http_client_requests_seconds_bucket{clientName="my-app.com",method="GET",outcome="SUCCESS",status="200",uri="/shops",le="0.001048576",investor="A", version="v1"} 0.0
http_client_requests_seconds_bucket{clientName="my-app.com",method="GET",outcome="SUCCESS",status="200",uri="/shops",le="0.002088576",investor="A", version="v1"} 1.0
Notice the 2 custom tags I added investor="A", version="v1". I'm looking for some code that may look like this,
@Autowire
private WebClient webclient; // Assume there is already a bean created for us
public Mono<String> getShopsList(String... extraTags) {
return webclient.baseUrl("http://my-app.com")
.build()
.get()
.uri("/shops")
.tags(extraTags) // Some extra tags I want callers of the method to pass. Note there are only 4-5 methods that call "getShopsList()" method
.retrieve()
.bodyToMono(String.class);
}
Can someone please help about the best way possible to achieve this?