Search code examples
javaspringprometheusopenlayersmicrometer

Change default micrometer metrics tag


I would like to track http requests to my Spring Java server without creating custom metrics

Lets say I have this default micrometer metric

http_server_requests_seconds_sum{error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="/TMS/{L}/{Z}/{Y}/{X}",} 3.5174407

is it possible to change the {L} so it matches what was in the url, for example if someone calls /TMS/OSM/3/4/4 it would be under

http_server_requests_seconds_sum{error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="/TMS/OSM/{Z}/{Y}/{X}",} 3.5174407

Solution

  • If this is a Spring-Boot 3 app, you can add an ObservationFilter that adds the missing value. You will have access to the request and the Obesrvation.Context will also contain a high cardinality key-value called url that you can add as a low cardinality key-value.

    Though, I would highly recommend against it since metrics should not have high cardinality tags, see here why: https://develotters.com/posts/high-cardinality/