@@ -156,9 +156,10 @@ void unknownServiceShouldBeUsedAsDefaultServiceName() {
156
156
@ Test
157
157
void springApplicationGroupNameShouldBeUsedAsDefaultServiceGroup () {
158
158
this .environment .setProperty ("spring.application.group" , "spring-boot" );
159
- assertThat (getAttributes ()).hasSize (2 )
159
+ assertThat (getAttributes ()).hasSize (3 )
160
160
.containsEntry ("service.name" , "unknown_service" )
161
- .containsEntry ("service.group" , "spring-boot" );
161
+ .containsEntry ("service.group" , "spring-boot" )
162
+ .containsEntry ("service.namespace" , "spring-boot" );
162
163
}
163
164
164
165
@ Test
@@ -167,6 +168,11 @@ void springApplicationNameShouldBeUsedAsDefaultServiceName() {
167
168
assertThat (getAttributes ()).hasSize (1 ).containsEntry ("service.name" , "spring-boot-app" );
168
169
}
169
170
171
+ @ Test
172
+ void serviceNamespaceShouldNotBePresentByDefault () {
173
+ assertThat (getAttributes ()).hasSize (1 ).doesNotContainKey ("service.namespace" );
174
+ }
175
+
170
176
@ Test
171
177
void resourceAttributesShouldTakePrecedenceOverSpringApplicationName () {
172
178
this .resourceAttributes .put ("service.name" , "spring-boot" );
@@ -192,18 +198,50 @@ void otelServiceNameShouldTakePrecedenceOverSpringApplicationName() {
192
198
void resourceAttributesShouldTakePrecedenceOverSpringApplicationGroupName () {
193
199
this .resourceAttributes .put ("service.group" , "spring-boot-app" );
194
200
this .environment .setProperty ("spring.application.group" , "spring-boot" );
195
- assertThat (getAttributes ()).hasSize (2 )
201
+ assertThat (getAttributes ()).hasSize (3 )
196
202
.containsEntry ("service.name" , "unknown_service" )
197
203
.containsEntry ("service.group" , "spring-boot-app" );
198
204
}
199
205
206
+ @ Test
207
+ void resourceAttributesShouldTakePrecedenceOverApplicationGroupNameForPopulatingServiceNamespace () {
208
+ this .resourceAttributes .put ("service.namespace" , "spring-boot-app" );
209
+ this .environment .setProperty ("spring.application.group" , "overriden" );
210
+ assertThat (getAttributes ()).hasSize (3 )
211
+ .containsEntry ("service.name" , "unknown_service" )
212
+ .containsEntry ("service.group" , "overriden" )
213
+ .containsEntry ("service.namespace" , "spring-boot-app" );
214
+ }
215
+
200
216
@ Test
201
217
void otelResourceAttributesShouldTakePrecedenceOverSpringApplicationGroupName () {
202
218
this .environmentVariables .put ("OTEL_RESOURCE_ATTRIBUTES" , "service.group=spring-boot" );
203
219
this .environment .setProperty ("spring.application.group" , "spring-boot-app" );
204
- assertThat (getAttributes ()).hasSize (2 )
220
+ assertThat (getAttributes ()).hasSize (3 )
205
221
.containsEntry ("service.name" , "unknown_service" )
206
- .containsEntry ("service.group" , "spring-boot" );
222
+ .containsEntry ("service.group" , "spring-boot" )
223
+ .containsEntry ("service.namespace" , "spring-boot-app" );
224
+ }
225
+
226
+ @ Test
227
+ void otelResourceAttributesShouldTakePrecedenceOverSpringApplicationGroupNameForServiceNamespace () {
228
+ this .environmentVariables .put ("OTEL_RESOURCE_ATTRIBUTES" , "service.namespace=spring-boot" );
229
+ this .environment .setProperty ("spring.application.group" , "overriden" );
230
+ ;
231
+ assertThat (getAttributes ()).hasSize (3 )
232
+ .containsEntry ("service.group" , "overriden" )
233
+ .containsEntry ("service.namespace" , "spring-boot" );
234
+ }
235
+
236
+ @ Test
237
+ void shouldUseServiceGroupForServiceNamespaceIfServiceGroupIsSet () {
238
+ this .environment .setProperty ("spring.application.group" , "alpha" );
239
+ assertThat (getAttributes ()).containsEntry ("service.namespace" , "alpha" );
240
+ }
241
+
242
+ @ Test
243
+ void shouldNotSetServiceNamespaceIfServiceGroupIsNotSet () {
244
+ assertThat (getAttributes ()).doesNotContainKey ("service.namespace" );
207
245
}
208
246
209
247
private Map <String , String > getAttributes () {
0 commit comments