Skip to content

Commit 9680219

Browse files
crossoverJieasweet-confluent
authored andcommitted
fix test
1 parent 6121b30 commit 9680219

File tree

2 files changed

+102
-25
lines changed
  • instrumentation
    • armeria/armeria-grpc-1.14/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/armeria/grpc/v1_14
    • grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6

2 files changed

+102
-25
lines changed

instrumentation/armeria/armeria-grpc-1.14/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/armeria/grpc/v1_14/ArmeriaGrpcTest.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import example.Helloworld;
2323
import io.grpc.Status;
2424
import io.grpc.stub.StreamObserver;
25+
import io.opentelemetry.api.common.AttributeKey;
2526
import io.opentelemetry.api.trace.SpanKind;
2627
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2728
import io.opentelemetry.semconv.incubating.MessageIncubatingAttributes;
@@ -33,6 +34,15 @@ class ArmeriaGrpcTest {
3334
@RegisterExtension
3435
static final AgentInstrumentationExtension testing = AgentInstrumentationExtension.create();
3536

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+
3646
@RegisterExtension
3747
static final ServerExtension server =
3848
new ServerExtension() {
@@ -63,12 +73,12 @@ void grpcInstrumentation() {
6373
GreeterGrpc.GreeterBlockingStub client =
6474
GrpcClients.builder(server.httpUri()).build(GreeterGrpc.GreeterBlockingStub.class);
6575

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));
7078

7179
assertThat(response.getMessage()).isEqualTo("Hello test");
80+
int requestSerializedSize = request.getSerializedSize();
81+
int responseSerializedSize = response.getSerializedSize();
7282

7383
testing.waitAndAssertTraces(
7484
trace ->
@@ -85,6 +95,8 @@ void grpcInstrumentation() {
8595
equalTo(RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()),
8696
equalTo(SERVER_ADDRESS, "127.0.0.1"),
8797
equalTo(SERVER_PORT, (long) server.httpPort()))
98+
equalTo(RPC_CLIENT_RESPONSE_BODY_SIZE, responseSerializedSize),
99+
equalTo(RPC_CLIENT_REQUEST_BODY_SIZE, requestSerializedSize))
88100
.hasEventsSatisfyingExactly(
89101
event ->
90102
event
@@ -110,6 +122,8 @@ void grpcInstrumentation() {
110122
equalTo(RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()),
111123
equalTo(SERVER_ADDRESS, "127.0.0.1"),
112124
equalTo(SERVER_PORT, server.httpPort()))
125+
equalTo(RPC_SERVER_REQUEST_BODY_SIZE, responseSerializedSize),
126+
equalTo(RPC_SERVER_RESPONSE_BODY_SIZE, requestSerializedSize))
113127
.hasEventsSatisfyingExactly(
114128
event ->
115129
event

0 commit comments

Comments
 (0)