diff --git a/kstreamplify-spring-boot/src/main/java/com/michelin/kstreamplify/opentelemetry/OpenTelemetryConfig.java b/kstreamplify-spring-boot/src/main/java/com/michelin/kstreamplify/opentelemetry/OpenTelemetryConfig.java index 4b5624dc..6a830217 100644 --- a/kstreamplify-spring-boot/src/main/java/com/michelin/kstreamplify/opentelemetry/OpenTelemetryConfig.java +++ b/kstreamplify-spring-boot/src/main/java/com/michelin/kstreamplify/opentelemetry/OpenTelemetryConfig.java @@ -29,7 +29,7 @@ public class OpenTelemetryConfig { /** * The OpenTelemetry resource attributes. */ - @Value("${otel.resource.attributes:}") + @Value("${otel.resource.attributes:#{null}}") private String otelResourceAttributes; /** diff --git a/kstreamplify-spring-boot/src/test/java/com/michelin/kstreamplify/opentelemetry/OpenTelemetryConfigTest.java b/kstreamplify-spring-boot/src/test/java/com/michelin/kstreamplify/opentelemetry/OpenTelemetryConfigTest.java index ed45a0a4..d045b669 100644 --- a/kstreamplify-spring-boot/src/test/java/com/michelin/kstreamplify/opentelemetry/OpenTelemetryConfigTest.java +++ b/kstreamplify-spring-boot/src/test/java/com/michelin/kstreamplify/opentelemetry/OpenTelemetryConfigTest.java @@ -1,5 +1,6 @@ package com.michelin.kstreamplify.opentelemetry; +import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -18,6 +19,32 @@ class OpenTelemetryConfigTest { private final OpenTelemetryConfig openTelemetryConfig = new OpenTelemetryConfig(); + @Test + void shouldNotAddTagsToMetricsWhenNull() { + openTelemetryConfig.setOtelResourceAttributes(null); + MeterRegistryCustomizer customizer = openTelemetryConfig.addTagsOnMetrics(); + + MeterRegistry meterRegistry = new OpenTelemetryMeterRegistry(); + customizer.customize(meterRegistry); + meterRegistry.counter("fakeCounterMetric"); + + assertEquals("fakeCounterMetric", meterRegistry.getMeters().get(0).getId().getName()); + assertTrue(meterRegistry.getMeters().get(0).getId().getTags().isEmpty()); + } + + @Test + void shouldNotAddTagsToMetricsWhenEmpty() { + openTelemetryConfig.setOtelResourceAttributes(EMPTY); + MeterRegistryCustomizer customizer = openTelemetryConfig.addTagsOnMetrics(); + + MeterRegistry meterRegistry = new OpenTelemetryMeterRegistry(); + customizer.customize(meterRegistry); + meterRegistry.counter("fakeCounterMetric"); + + assertEquals("fakeCounterMetric", meterRegistry.getMeters().get(0).getId().getName()); + assertTrue(meterRegistry.getMeters().get(0).getId().getTags().isEmpty()); + } + @Test void shouldAddTagsToMetricsWhenOpenTelemetryRegistry() { openTelemetryConfig.setOtelResourceAttributes("tagName=tagValue,tagName2=tagValue2");