Skip to content

Commit

Permalink
Static import RPC semconv constants in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Nov 6, 2024
1 parent 2371589 commit 08b09bb
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.trace.SpanKind;
Expand Down Expand Up @@ -132,12 +135,10 @@ void testApacheDubboBase() throws ReflectiveOperationException {
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
equalTo(RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"),
equalTo(RPC_METHOD, "$invoke"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand Down Expand Up @@ -166,12 +167,12 @@ void testApacheDubboBase() throws ReflectiveOperationException {
.hasParent(trace.getSpan(1))
.hasAttributesSatisfying(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
equalTo(RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(NETWORK_TYPE, AbstractAssert::isNull))));
Expand Down Expand Up @@ -226,12 +227,10 @@ void testApacheDubboTest()
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invokeAsync"),
equalTo(RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"),
equalTo(RPC_METHOD, "$invokeAsync"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand Down Expand Up @@ -260,12 +259,12 @@ void testApacheDubboTest()
.hasParent(trace.getSpan(1))
.hasAttributesSatisfying(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
equalTo(RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.trace.SpanKind;
Expand Down Expand Up @@ -175,12 +178,10 @@ void testDubboChain() throws ReflectiveOperationException {
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
equalTo(RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"),
equalTo(RPC_METHOD, "$invoke"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand Down Expand Up @@ -209,12 +210,12 @@ void testDubboChain() throws ReflectiveOperationException {
.hasParent(trace.getSpan(1))
.hasAttributesSatisfying(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
equalTo(RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand All @@ -230,12 +231,10 @@ void testDubboChain() throws ReflectiveOperationException {
.hasParent(trace.getSpan(2))
.hasAttributesSatisfyingExactly(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
equalTo(RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"),
equalTo(RPC_METHOD, "$invoke"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand Down Expand Up @@ -264,12 +263,12 @@ void testDubboChain() throws ReflectiveOperationException {
.hasParent(trace.getSpan(3))
.hasAttributesSatisfying(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
equalTo(RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand Down Expand Up @@ -346,12 +345,10 @@ void testDubboChainInJvm() throws ReflectiveOperationException {
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
equalTo(RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"),
equalTo(RPC_METHOD, "$invoke"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand Down Expand Up @@ -380,12 +377,12 @@ void testDubboChainInJvm() throws ReflectiveOperationException {
.hasParent(trace.getSpan(1))
.hasAttributesSatisfying(
equalTo(
RpcIncubatingAttributes.RPC_SYSTEM,
RPC_SYSTEM,
RpcIncubatingAttributes.RpcSystemIncubatingValues.APACHE_DUBBO),
equalTo(
RpcIncubatingAttributes.RPC_SERVICE,
RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
equalTo(RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_GRPC_STATUS_CODE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM;
import static org.assertj.core.api.Assertions.assertThat;

import com.linecorp.armeria.client.grpc.GrpcClients;
Expand All @@ -21,7 +25,6 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.semconv.incubating.MessageIncubatingAttributes;
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand Down Expand Up @@ -76,12 +79,10 @@ void grpcInstrumentation() {
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "grpc"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "example.Greeter"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "SayHello"),
equalTo(
RpcIncubatingAttributes.RPC_GRPC_STATUS_CODE,
(long) Status.Code.OK.value()),
equalTo(RPC_SYSTEM, "grpc"),
equalTo(RPC_SERVICE, "example.Greeter"),
equalTo(RPC_METHOD, "SayHello"),
equalTo(RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()),
equalTo(SERVER_ADDRESS, "127.0.0.1"),
equalTo(SERVER_PORT, (long) server.httpPort()))
.hasEventsSatisfyingExactly(
Expand All @@ -103,12 +104,10 @@ void grpcInstrumentation() {
.hasKind(SpanKind.SERVER)
.hasParent(trace.getSpan(1))
.hasAttributesSatisfyingExactly(
equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "grpc"),
equalTo(RpcIncubatingAttributes.RPC_SERVICE, "example.Greeter"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "SayHello"),
equalTo(
RpcIncubatingAttributes.RPC_GRPC_STATUS_CODE,
(long) Status.Code.OK.value()),
equalTo(RPC_SYSTEM, "grpc"),
equalTo(RPC_SERVICE, "example.Greeter"),
equalTo(RPC_METHOD, "SayHello"),
equalTo(RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()),
equalTo(SERVER_ADDRESS, "127.0.0.1"),
equalTo(SERVER_PORT, server.httpPort()))
.hasEventsSatisfyingExactly(
Expand Down
Loading

0 comments on commit 08b09bb

Please sign in to comment.