Affects: 6.1.10


Hi all! I found that restTemplate micrometer's metrics are not reporting the right value for the uri tag if the url is passed as URI

Doing this call

restTemplate.getForObject(URI.create("https://httpbin.org/get"), String.class);

the uri tag has the value none (for metrics http.client.requests)

The same but passing the url as String

restTemplate.getForObject("https://httpbin.org/get", String.class);

give the expected result, the uri tag has the value /get (for metrics http.client.requests)

Looking at the code it seems to be done on purpose. Here null is passed to uriTemplate param which is the value used by the observation.

Is this behavior correct? If so, what are the reasons? It seems to me that even by passing a URI we could have a tag with a value better than none

Thanks!

Comment From: bclozel

This is by design.

With metrics, low cardinality must avoid cardinality explosion - the total number of possible values must be bounded. If not, memory grows infinitely to track all dimensions and this can lead to out of memory errors. If we accepted all URI instances and used their String representation for the "uri" tag, this could create a denial of service vulnerability in Spring.

The only way to limit the number of "uri" tags is to use URI templates, which should have a limited number of values in your application.

See the "tag values" section of the micrometer documentation.

Thanks!