Skip to content

Commit 7e21d52

Browse files
committed
Ensure that service.namespace is set to same value in OtlpMetricsPropertiesConfigAdapter
Signed-off-by: Vanio Begic <[email protected]>
1 parent 2908cc5 commit 7e21d52

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public Map<String, String> resourceAttributes() {
8282
.asMap();
8383
attributes.computeIfAbsent("service.name", (key) -> getApplicationName());
8484
attributes.computeIfAbsent("service.group", (key) -> getApplicationGroup());
85+
attributes.computeIfAbsent("service.namespace", (key) -> getApplicationGroup());
8586
return Collections.unmodifiableMap(attributes);
8687
}
8788

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ private Resource toResource(Environment environment, OpenTelemetryProperties pro
8080
.asMap();
8181
attributes.computeIfAbsent("service.name", (key) -> getApplicationName(environment));
8282
attributes.computeIfAbsent("service.group", (key) -> getApplicationGroup(environment));
83-
// See https://github.com/spring-projects/spring-boot/issues/44411 for potential information about deprecation of "service.group" attribute
83+
// See https://github.com/spring-projects/spring-boot/issues/44411 for potential
84+
// information about deprecation of "service.group" attribute
8485
attributes.computeIfAbsent("service.namespace", (key) -> getApplicationGroup(environment));
8586
attributes.forEach(builder::put);
8687
return builder.build();

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ void shouldUseDefaultApplicationGroupIfApplicationGroupIsNotSet() {
163163
assertThat(createAdapter().resourceAttributes()).doesNotContainKey("service.group");
164164
}
165165

166+
@Test
167+
void shouldUseServiceGroupForServiceNamespaceIfServiceGroupIsSet() {
168+
this.environment.setProperty("spring.application.group", "alpha");
169+
assertThat(createAdapter().resourceAttributes()).containsEntry("service.namespace", "alpha");
170+
}
171+
172+
@Test
173+
void shouldNotSetServiceNamespaceIfServiceGroupIsNotSet() {
174+
assertThat(createAdapter().resourceAttributes()).doesNotContainKey("service.namespace");
175+
}
176+
166177
private OtlpMetricsPropertiesConfigAdapter createAdapter() {
167178
return new OtlpMetricsPropertiesConfigAdapter(this.properties, this.openTelemetryProperties,
168179
this.connectionDetails, this.environment);

0 commit comments

Comments
 (0)