简体   繁体   English

是否有可能在运行时添加自定义 spring 引导指标标签?

[英]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.我正在使用带有 micrometer-registry-prometheus 的 Spring 引导,尝试存储来自 http 标头、安全上下文等的自定义标签。

So I found MeterFilter iterface and tried to use it to store the data I need.于是我找到了 MeterFilter iterface,并尝试用它来存储我需要的数据。

But MeterFilter method works after request is completed, so at that point I don't have any information about request.但是 MeterFilter 方法在请求完成后起作用,所以那时我没有任何关于请求的信息。

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.如果您使用的是 Spring MVC,您可以定义一个实现WebMvcTagsProvider的 bean,以完全控制添加到请求-响应交换指标的标签。 Alternatively, you can define a bean that implements WebMvcTagsContributor to add to the default tags.或者,您可以定义一个实现WebMvcTagsContributor的 bean 以添加到默认标签。 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.同样,如果您使用 Spring WebFlux,您可以定义实现WebFluxTagsProviderWebFluxTagsContributor的 bean 来完全控制标签并分别贡献额外的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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