From 7aeb21e6aef76dbeae600ff0691b4f3b91780f36 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Sun, 23 Apr 2023 07:47:54 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=A9=94=ED=8A=B8=EB=A6=AD=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9(#507)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/MetricsConfig.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/nanal/backend/global/config/MetricsConfig.java 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