We are using Spring Boot 2.1.4 and the micrometer-registry-prometheus
dependency to capture metrics.
We have a case where a Spring Boot service uses a RestTemplate to call out to another service. The metrics being generated by this call contain the actual values in the URI instead of the templated values.
For example, in the /actuator/prometheus
endpoint, I see entries like this:
http_client_requests_seconds_count{clientName="someClient",method="GET",status="200",uri="/person/lookup?firstName=Tony&lastName=Soprano",} 1.0
Based on the documentation, I would expect to see the variable names rather than the values, like this:
http_client_requests_seconds_count{clientName="someClient",method="GET",status="200",uri="/person/lookup?firstName={firstName}&lastName={lastName}",} 1.0
Is there a way to get the default http.client.requests
metric values to use the templated values for the URI tag?
The Spring documentation at https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-http-clients says this about the uri tag:
Request’s URI template prior to variable substitution, if possible (for example, /api/person/{id})
How do we make it possible for the variable substitution to take place?
I assume you are using the RestTemplateBuilder
to build your RestTemplate
as otherwise you wouldn't be getting the metrics registered.
Are you actually passing a templated url into RestTemplate
s exchange methods and pass along the params for subsbitution? Works-for-me on 2.1.4.RELEASE
and 2.2.1.RELEASE
.
template.getForObject("http://localhost:" + this.serverPort + "/hello/{id}",
String.class, Collections.singletonMap("id", "loop"));
Results in:
http_client_requests_seconds_count{application="micrometered2",clientName="localhost",method="GET",outcome="SUCCESS",status="200",uri="/hello/{id}",} 23.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With