diff --git a/src/main/java/com/nanal/backend/global/config/MetricsConfig.java b/src/main/java/com/nanal/backend/global/config/MetricsConfig.java new file mode 100644 index 00000000..73f4166b --- /dev/null +++ b/src/main/java/com/nanal/backend/global/config/MetricsConfig.java @@ -0,0 +1,36 @@ +package com.nanal.backend.global.config; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; +import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; +import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider; +import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsProvider; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Configuration +public class MetricsConfig { + + @Bean + MeterRegistryCustomizer metricsCommonTags() { + return registry -> registry.config().commonTags("app_version", getAppVersion()); + } + + @Bean + WebMvcTagsProvider webMvcTagsProvider() { + return new DefaultWebMvcTagsProvider() { + @Override + public Iterable getTags(HttpServletRequest request, HttpServletResponse response, Object handler, Throwable exception) { + return Tags.of(super.getTags(request, response, handler, exception)).and("app_version", getAppVersion()); + } + }; + } + + private String getAppVersion() { + return "1.0.0"; // or read from configuration or environment variable + } +} \ No newline at end of file