Skip to content

Commit

Permalink
Merge pull request #509 from On-Log/develop
Browse files Browse the repository at this point in the history
[feat] 메트릭 통합
  • Loading branch information
isprogrammingfun authored Apr 22, 2023
2 parents 72b6603 + bbf0be6 commit c59bcbd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/java/com/nanal/backend/global/config/MetricsConfig.java
Original file line number Diff line number Diff line change
@@ -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<MeterRegistry> metricsCommonTags() {
return registry -> registry.config().commonTags("app_version", getAppVersion());
}

@Bean
WebMvcTagsProvider webMvcTagsProvider() {
return new DefaultWebMvcTagsProvider() {
@Override
public Iterable<Tag> 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
}
}

0 comments on commit c59bcbd

Please sign in to comment.