1616
1717package com .splunk .opentelemetry .opamp ;
1818
19+ import static io .opentelemetry .semconv .ServiceAttributes .SERVICE_NAME ;
20+ import static io .opentelemetry .semconv .ServiceAttributes .SERVICE_VERSION ;
21+ import static io .opentelemetry .semconv .incubating .DeploymentIncubatingAttributes .DEPLOYMENT_ENVIRONMENT_NAME ;
22+ import static io .opentelemetry .semconv .incubating .OsIncubatingAttributes .OS_NAME ;
23+ import static io .opentelemetry .semconv .incubating .OsIncubatingAttributes .OS_TYPE ;
24+ import static io .opentelemetry .semconv .incubating .OsIncubatingAttributes .OS_VERSION ;
25+ import static io .opentelemetry .semconv .incubating .ServiceIncubatingAttributes .SERVICE_NAMESPACE ;
1926import static org .assertj .core .api .Assertions .assertThat ;
2027
28+ import io .opentelemetry .api .common .AttributeKey ;
29+ import io .opentelemetry .api .common .Attributes ;
2130import io .opentelemetry .instrumentation .testing .internal .AutoCleanupExtension ;
2231import io .opentelemetry .opamp .client .OpampClient ;
2332import io .opentelemetry .opamp .client .internal .response .MessageData ;
33+ import io .opentelemetry .sdk .resources .Resource ;
2434import io .opentelemetry .testing .internal .armeria .common .HttpResponse ;
2535import io .opentelemetry .testing .internal .armeria .common .HttpStatus ;
2636import io .opentelemetry .testing .internal .armeria .common .MediaType ;
2737import io .opentelemetry .testing .internal .armeria .testing .junit5 .server .mock .MockWebServerExtension ;
38+ import io .opentelemetry .testing .internal .armeria .testing .junit5 .server .mock .RecordedRequest ;
2839import java .util .Collections ;
2940import java .util .Map ;
3041import java .util .concurrent .CompletableFuture ;
3344import opamp .proto .AgentConfigFile ;
3445import opamp .proto .AgentConfigMap ;
3546import opamp .proto .AgentRemoteConfig ;
47+ import opamp .proto .AgentToServer ;
48+ import opamp .proto .AnyValue ;
49+ import opamp .proto .KeyValue ;
3650import opamp .proto .ServerErrorResponse ;
3751import opamp .proto .ServerToAgent ;
3852import org .jetbrains .annotations .Nullable ;
@@ -65,6 +79,22 @@ static void cleanUp() {
6579 @ Test
6680 void testOpamp () throws Exception {
6781 // given
82+ Attributes attributes =
83+ Attributes .of (
84+ DEPLOYMENT_ENVIRONMENT_NAME ,
85+ "test-deployment-env" ,
86+ SERVICE_NAME ,
87+ "test-service" ,
88+ SERVICE_VERSION ,
89+ "test-ver" ,
90+ SERVICE_NAMESPACE ,
91+ "test-ns" )
92+ .toBuilder ()
93+ .put (OS_NAME , "test-os-name" )
94+ .put (OS_TYPE , "test-os-type" )
95+ .put (OS_VERSION , "test-os-ver" )
96+ .build ();
97+ Resource resource = Resource .create (attributes );
6898 Map <String , AgentConfigFile > configMap =
6999 Collections .singletonMap (
70100 "test-key" ,
@@ -82,7 +112,7 @@ void testOpamp() throws Exception {
82112 OpampClient client =
83113 OpampActivator .startOpampClient (
84114 server .httpUri ().toString (),
85- "test" ,
115+ resource ,
86116 new OpampClient .Callbacks () {
87117 @ Override
88118 public void onConnect (OpampClient opampClient ) {}
@@ -113,5 +143,30 @@ public void onMessage(OpampClient opampClient, MessageData messageData) {
113143 // then
114144 assertThat (remoteConfig ).isNotNull ();
115145 assertThat (remoteConfig .config .config_map .get ("test-key" ).body .utf8 ()).isEqualTo ("test-value" );
146+
147+ RecordedRequest recordedRequest = server .takeRequest ();
148+ byte [] body = recordedRequest .request ().content ().array ();
149+ AgentToServer agentToServer = AgentToServer .ADAPTER .decode (body );
150+ assertIdentifying (agentToServer , DEPLOYMENT_ENVIRONMENT_NAME , "test-deployment-env" );
151+ assertIdentifying (agentToServer , SERVICE_NAME , "test-service" );
152+ assertIdentifying (agentToServer , SERVICE_VERSION , "test-ver" );
153+ assertIdentifying (agentToServer , SERVICE_NAMESPACE , "test-ns" );
154+ assertNonIdentifying (agentToServer , OS_NAME , "test-os-name" );
155+ assertNonIdentifying (agentToServer , OS_TYPE , "test-os-type" );
156+ assertNonIdentifying (agentToServer , OS_VERSION , "test-os-ver" );
157+ }
158+
159+ private void assertIdentifying (
160+ AgentToServer agentToServer , AttributeKey <String > attr , String expected ) {
161+ KeyValue kv =
162+ new KeyValue (attr .getKey (), new AnyValue .Builder ().string_value (expected ).build ());
163+ assertThat (agentToServer .agent_description .identifying_attributes ).contains (kv );
164+ }
165+
166+ private void assertNonIdentifying (
167+ AgentToServer agentToServer , AttributeKey <String > attr , String expected ) {
168+ KeyValue kv =
169+ new KeyValue (attr .getKey (), new AnyValue .Builder ().string_value (expected ).build ());
170+ assertThat (agentToServer .agent_description .non_identifying_attributes ).contains (kv );
116171 }
117172}
0 commit comments