@@ -73,6 +73,14 @@ void getServiceName() {
7373 map .put ("otel.service.name" , "my-service-3" );
7474 map .put ("otel.resource.attributes" , "service.name=my-service-4" );
7575 testServiceName (map , "my-service-3" , "service name takes precedence over resource attributes" );
76+
77+ map .clear ();
78+ map .put ("otel.resource.attributes" , "" );
79+ testServiceName (map , "unknown_service:java" , "default service name should be provided" );
80+
81+ map .clear ();
82+ map .put ("otel.resource.attributes" , "service.name=" );
83+ testServiceName (map , "unknown_service:java" , "default service name should be provided" );
7684 }
7785
7886 private static void testServiceName (
@@ -83,4 +91,28 @@ private static void testServiceName(
8391 .describedAs (description )
8492 .isEqualTo (expectedServiceName );
8593 }
94+
95+ @ Test
96+ void getServiceEnvironment () {
97+ Map <String , String > map = Collections .emptyMap ();
98+ testServiceEnvironment (map , null , "no environment by default" );
99+
100+ map = Collections .singletonMap ("otel.resource.attributes" , "deployment.environment.name=test1" );
101+ testServiceEnvironment (map , "test1" , "environment set through resource attribute" );
102+
103+ map = Collections .singletonMap ("otel.resource.attributes" , "deployment.environment=test2" );
104+ testServiceEnvironment (map , "test2" , "environment set through legacy resource attribute" );
105+
106+ map = Collections .singletonMap ("otel.resource.attributes" , "deployment.environment=test3,deployment.environment.name=test4" );
107+ testServiceEnvironment (map , "test4" , "when both set semconv attribute takes precedence" );
108+
109+ }
110+
111+ private static void testServiceEnvironment (
112+ Map <String , String > map , String expectedEnvironment , String description ) {
113+ ConfigProperties configProperties = DefaultConfigProperties .createFromMap (map );
114+ assertThat (CentralConfig .getServiceEnvironment (configProperties ))
115+ .describedAs (description )
116+ .isEqualTo (expectedEnvironment );
117+ }
86118}
0 commit comments