潘志宝
2024-10-10 9100b0c14dca46366cfe79336eb85d5f0ca793af
提交 | 用户 | 时间
e7c126 1 package com.iailab.framework.tracer.config;
H 2
3 import io.micrometer.core.instrument.MeterRegistry;
4 import org.springframework.beans.factory.annotation.Value;
5 import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
6 import org.springframework.boot.autoconfigure.AutoConfiguration;
7 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
8 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9 import org.springframework.context.annotation.Bean;
10 import org.springframework.context.annotation.Configuration;
11
12 /**
13  * Metrics 配置类
14  *
15  * @author iailab
16  */
17 @AutoConfiguration
18 @ConditionalOnClass({MeterRegistryCustomizer.class})
19 @ConditionalOnProperty(prefix = "iailab.metrics", value = "enable", matchIfMissing = true) // 允许使用 iailab.metrics.enable=false 禁用 Metrics
20 public class IailabMetricsAutoConfiguration {
21
22     @Bean
23     public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags(
24             @Value("${spring.application.name}") String applicationName) {
25         return registry -> registry.config().commonTags("application", applicationName);
26     }
27
28 }