Skip to content

Commit 7fd29cf

Browse files
committed
Polish "Add support for OpenTelemetry's service.namespace"
See gh-44499
1 parent cf2353b commit 7fd29cf

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public OpenTelemetryResourceAttributes(Environment environment, Map<String, Stri
8686
* <p>
8787
* Additionally, {@code spring.application.name} or {@code unknown_service} will be
8888
* used as the default for {@code service.name}, and {@code spring.application.group}
89-
* will serve as the default for {@code service.group}.
89+
* will serve as the default for {@code service.group} and {@code service.namespace}.
9090
* @param consumer the {@link BiConsumer} to apply
9191
*/
9292
public void applyTo(BiConsumer<String, String> consumer) {
@@ -97,8 +97,8 @@ public void applyTo(BiConsumer<String, String> consumer) {
9797
attributes.put(name, value);
9898
}
9999
});
100-
attributes.computeIfAbsent("service.name", (k) -> getApplicationName());
101-
attributes.computeIfAbsent("service.group", (k) -> getApplicationGroup());
100+
attributes.computeIfAbsent("service.name", (key) -> getApplicationName());
101+
attributes.computeIfAbsent("service.group", (key) -> getApplicationGroup());
102102
attributes.computeIfAbsent("service.namespace", (key) -> getServiceNamespace());
103103
attributes.forEach(consumer);
104104
}
@@ -107,9 +107,12 @@ private String getApplicationName() {
107107
return this.environment.getProperty("spring.application.name", DEFAULT_SERVICE_NAME);
108108
}
109109

110+
/**
111+
* Returns the application group.
112+
* @return the application group
113+
* @deprecated since 3.5.0 for removal in 3.7.0
114+
*/
110115
@Deprecated(since = "3.5.0", forRemoval = true)
111-
// See https://github.com/spring-projects/spring-boot/issues/44411 for potential
112-
// information about deprecation of "service.group" attribute
113116
private String getApplicationGroup() {
114117
String applicationGroup = this.environment.getProperty("spring.application.group");
115118
return (StringUtils.hasLength(applicationGroup)) ? applicationGroup : null;

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfigurationTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ void shouldNotApplySpringApplicationGroupIfNotSet() {
110110
void shouldApplyServiceNamespaceIfApplicationGroupIsSet() {
111111
this.runner.withPropertyValues("spring.application.group=my-group").run((context) -> {
112112
Resource resource = context.getBean(Resource.class);
113-
assertThat(resource.getAttributes().asMap()).containsEntry(AttributeKey.stringKey("service.namespace"), "my-group");
113+
assertThat(resource.getAttributes().asMap()).containsEntry(AttributeKey.stringKey("service.namespace"),
114+
"my-group");
114115
});
115116
}
116117

117118
@Test
118-
void shouldNOtApplyServiceNamespaceIfApplicationGroupIsNotSet() {
119-
this.runner.run((context -> {
119+
void shouldNotApplyServiceNamespaceIfApplicationGroupIsNotSet() {
120+
this.runner.run(((context) -> {
120121
Resource resource = context.getBean(Resource.class);
121122
assertThat(resource.getAttributes().asMap()).doesNotContainKey(AttributeKey.stringKey("service.namespace"));
122123
}));
@@ -172,7 +173,7 @@ void shouldRegisterSdkMeterProviderIfAvailable() {
172173
}
173174

174175
@Configuration(proxyBeanMethods = false)
175-
private static final class UserConfiguration {
176+
static class UserConfiguration {
176177

177178
@Bean
178179
OpenTelemetry customOpenTelemetry() {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryResourceAttributesTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ void otelResourceAttributesShouldTakePrecedenceOverSpringApplicationGroupName()
227227
void otelResourceAttributesShouldTakePrecedenceOverSpringApplicationGroupNameForServiceNamespace() {
228228
this.environmentVariables.put("OTEL_RESOURCE_ATTRIBUTES", "service.namespace=spring-boot");
229229
this.environment.setProperty("spring.application.group", "overriden");
230-
;
231230
assertThat(getAttributes()).hasSize(3)
232231
.containsEntry("service.group", "overriden")
233232
.containsEntry("service.namespace", "spring-boot");

0 commit comments

Comments
 (0)