-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #509 from On-Log/develop
[feat] 메트릭 통합
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/com/nanal/backend/global/config/MetricsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |