diff --git a/implementation/src/main/java/io/smallrye/metrics/legacyapi/LegacyMetricRegistryAdapter.java b/implementation/src/main/java/io/smallrye/metrics/legacyapi/LegacyMetricRegistryAdapter.java index 478e7bc4..5ad78b71 100644 --- a/implementation/src/main/java/io/smallrye/metrics/legacyapi/LegacyMetricRegistryAdapter.java +++ b/implementation/src/main/java/io/smallrye/metrics/legacyapi/LegacyMetricRegistryAdapter.java @@ -48,6 +48,14 @@ public class LegacyMetricRegistryAdapter implements MetricRegistry { protected static final String MP_APPLICATION_NAME_VAR = "mp.metrics.appName"; + protected static final String MP_DEFAULT_APPLICATION_NAME_VAR = "mp.metrics.defaultAppName"; + protected volatile static io.micrometer.core.instrument.Tag DEFAULT_APP_NAME_TAG = null; + + /* + * Set by user on the server-level with MP Config property mp.metrics.defaultAppName + */ + private final String defaultAppNameValue; + private final Map constructedMeters = new ConcurrentHashMap<>(); private final Map metadataMap = new ConcurrentHashMap<>(); @@ -176,11 +184,13 @@ public LegacyMetricRegistryAdapter(String scope, MeterRegistry registry, Applica this.scope = scope; this.registry = registry; - this.applicationMPConfigAppNameTagCache = new ConcurrentHashMap(); + applicationMPConfigAppNameTagCache = new ConcurrentHashMap(); applicationMap = new ConcurrentHashMap>(); - this.resolveMPConfigGlobalTagsByServer(); + defaultAppNameValue = resolveMPConfigDefaultAppNameTag(); + + resolveMPConfigGlobalTagsByServer(); if (scope != BASE_SCOPE && scope != VENDOR_SCOPE) { memberToMetricMappings = new MemberToMetricMappings(); @@ -288,6 +298,14 @@ private Tags combineApplicationTagsWithMPConfigAppNameTag(Tags tags) { } + private String resolveMPConfigDefaultAppNameTag() { + + Optional configVal = ConfigProvider.getConfig().getOptionalValue(MP_DEFAULT_APPLICATION_NAME_VAR, + String.class); + + return (configVal.isPresent()) ? configVal.get().trim() : null; + } + /** * This method will retrieve cached tag values for the mp.metrics.appName or resolve it and cache it * @@ -309,7 +327,11 @@ private synchronized io.micrometer.core.instrument.Tag resolveMPConfigAppNameTag */ io.micrometer.core.instrument.Tag tag = (appName == null) ? resolveMPConfigAppNameTagByServer() : resolveMPConfigAppNameTagByApplication(appName); - return tag; + + return (tag != null) ? tag + : (defaultAppNameValue != null) + ? io.micrometer.core.instrument.Tag.of(MP_APPLICATION_NAME_TAG, defaultAppNameValue) + : null; } /** @@ -325,7 +347,7 @@ private synchronized io.micrometer.core.instrument.Tag resolveMPConfigAppNameTag if (SERVER_LEVEL_MPCONFIG_APPLICATION_NAME_TAG == null) { SERVER_LEVEL_MPCONFIG_APPLICATION_NAME_TAG = new io.micrometer.core.instrument.Tag[1]; - //Using MP Config to retreive the mp.metrics.appName Config value + //Using MP Config to retrieve the mp.metrics.appName Config value Optional applicationName = ConfigProvider.getConfig().getOptionalValue(MP_APPLICATION_NAME_VAR, String.class);