22
22
import example .Helloworld ;
23
23
import io .grpc .Status ;
24
24
import io .grpc .stub .StreamObserver ;
25
+ import io .opentelemetry .api .common .AttributeKey ;
25
26
import io .opentelemetry .api .trace .SpanKind ;
26
27
import io .opentelemetry .instrumentation .testing .junit .AgentInstrumentationExtension ;
27
28
import io .opentelemetry .semconv .incubating .MessageIncubatingAttributes ;
@@ -33,6 +34,15 @@ class ArmeriaGrpcTest {
33
34
@ RegisterExtension
34
35
static final AgentInstrumentationExtension testing = AgentInstrumentationExtension .create ();
35
36
37
+ private static final AttributeKey <Long > RPC_CLIENT_REQUEST_BODY_SIZE =
38
+ AttributeKey .longKey ("rpc.client.request.body.size" );
39
+ private static final AttributeKey <Long > RPC_CLIENT_RESPONSE_BODY_SIZE =
40
+ AttributeKey .longKey ("rpc.client.response.body.size" );
41
+ private static final AttributeKey <Long > RPC_SERVER_REQUEST_BODY_SIZE =
42
+ AttributeKey .longKey ("rpc.server.request.body.size" );
43
+ private static final AttributeKey <Long > RPC_SERVER_RESPONSE_BODY_SIZE =
44
+ AttributeKey .longKey ("rpc.server.response.body.size" );
45
+
36
46
@ RegisterExtension
37
47
static final ServerExtension server =
38
48
new ServerExtension () {
@@ -63,12 +73,12 @@ void grpcInstrumentation() {
63
73
GreeterGrpc .GreeterBlockingStub client =
64
74
GrpcClients .builder (server .httpUri ()).build (GreeterGrpc .GreeterBlockingStub .class );
65
75
66
- Helloworld .Response response =
67
- testing .runWithSpan (
68
- "parent" ,
69
- () -> client .sayHello (Helloworld .Request .newBuilder ().setName ("test" ).build ()));
76
+ Helloworld .Request request = Helloworld .Request .newBuilder ().setName ("test" ).build ();
77
+ Helloworld .Response response = testing .runWithSpan ("parent" , () -> client .sayHello (request ));
70
78
71
79
assertThat (response .getMessage ()).isEqualTo ("Hello test" );
80
+ int requestSerializedSize = request .getSerializedSize ();
81
+ int responseSerializedSize = response .getSerializedSize ();
72
82
73
83
testing .waitAndAssertTraces (
74
84
trace ->
@@ -85,6 +95,8 @@ void grpcInstrumentation() {
85
95
equalTo (RPC_GRPC_STATUS_CODE , (long ) Status .Code .OK .value ()),
86
96
equalTo (SERVER_ADDRESS , "127.0.0.1" ),
87
97
equalTo (SERVER_PORT , (long ) server .httpPort ()))
98
+ equalTo (RPC_CLIENT_RESPONSE_BODY_SIZE , responseSerializedSize ),
99
+ equalTo (RPC_CLIENT_REQUEST_BODY_SIZE , requestSerializedSize ))
88
100
.hasEventsSatisfyingExactly (
89
101
event ->
90
102
event
@@ -110,6 +122,8 @@ void grpcInstrumentation() {
110
122
equalTo(RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()),
111
123
equalTo(SERVER_ADDRESS, " 127.0 .0 .1 "),
112
124
equalTo(SERVER_PORT, server.httpPort()))
125
+ equalTo(RPC_SERVER_REQUEST_BODY_SIZE, responseSerializedSize),
126
+ equalTo(RPC_SERVER_RESPONSE_BODY_SIZE, requestSerializedSize))
113
127
.hasEventsSatisfyingExactly(
114
128
event ->
115
129
event
0 commit comments