简体   繁体   中英

Is there a possibility to add custom spring boot metrics tags at runtime?

I'm using Spring Boot with micrometer-registry-prometheus, trying to store custom tags from http headers, security context, etc.

So I found MeterFilter iterface and tried to use it to store the data I need.

But MeterFilter method works after request is completed, so at that point I don't have any information about request.

Seems like the case is pretty common, is there any possibility to achieve it?

If you're using Spring MVC you can define a bean that implements WebMvcTagsProvider to take complete control over the tags that are added to metrics for request-response exchanges. Alternatively, you can define a bean that implements WebMvcTagsContributor to add to the default tags. Similarly, if you're using Spring WebFlux you can define beans that implements WebFluxTagsProvider and WebFluxTagsContributor to take complete control over the tags and contribute additional tags respectively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM