Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statically import semconv constants in tests #12575

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT;
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 org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.trace.SpanKind;
Expand All @@ -16,8 +21,6 @@
import io.opentelemetry.instrumentation.test.utils.PortUtils;
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.semconv.NetworkAttributes;
import io.opentelemetry.semconv.ServerAttributes;
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
import java.lang.reflect.Field;
import java.net.InetAddress;
Expand Down Expand Up @@ -135,23 +138,22 @@ void testApacheDubboBase() throws ReflectiveOperationException {
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
NETWORK_PEER_ADDRESS,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(String.class))),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
NETWORK_PEER_PORT,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(Long.class))),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand All @@ -170,14 +172,9 @@ void testApacheDubboBase() throws ReflectiveOperationException {
RpcIncubatingAttributes.RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
k -> k.isInstanceOf(String.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_TYPE, AbstractAssert::isNull))));
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(NETWORK_TYPE, AbstractAssert::isNull))));
}

@Test
Expand Down Expand Up @@ -235,23 +232,22 @@ void testApacheDubboTest()
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invokeAsync"),
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
NETWORK_PEER_ADDRESS,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(String.class))),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
NETWORK_PEER_PORT,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(Long.class))),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand All @@ -270,14 +266,10 @@ void testApacheDubboTest()
RpcIncubatingAttributes.RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
k -> k.isInstanceOf(String.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT;
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 org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.trace.SpanKind;
Expand All @@ -18,8 +23,6 @@
import io.opentelemetry.instrumentation.test.utils.PortUtils;
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.semconv.NetworkAttributes;
import io.opentelemetry.semconv.ServerAttributes;
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
import java.lang.reflect.Field;
import java.net.InetAddress;
Expand Down Expand Up @@ -178,23 +181,22 @@ void testDubboChain() throws ReflectiveOperationException {
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
NETWORK_PEER_ADDRESS,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(String.class))),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
NETWORK_PEER_PORT,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(Long.class))),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand All @@ -213,14 +215,10 @@ void testDubboChain() throws ReflectiveOperationException {
RpcIncubatingAttributes.RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
k -> k.isInstanceOf(String.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand All @@ -238,23 +236,22 @@ void testDubboChain() throws ReflectiveOperationException {
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
NETWORK_PEER_ADDRESS,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(String.class))),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
NETWORK_PEER_PORT,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(Long.class))),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand All @@ -273,14 +270,10 @@ void testDubboChain() throws ReflectiveOperationException {
RpcIncubatingAttributes.RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
k -> k.isInstanceOf(String.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand Down Expand Up @@ -359,23 +352,22 @@ void testDubboChainInJvm() throws ReflectiveOperationException {
RpcIncubatingAttributes.RPC_SERVICE,
"org.apache.dubbo.rpc.service.GenericService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
satisfies(
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
equalTo(SERVER_ADDRESS, "localhost"),
satisfies(SERVER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
NETWORK_PEER_ADDRESS,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(String.class))),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
NETWORK_PEER_PORT,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
val -> assertThat(val).isInstanceOf(Long.class))),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand All @@ -394,14 +386,10 @@ void testDubboChainInJvm() throws ReflectiveOperationException {
RpcIncubatingAttributes.RPC_SERVICE,
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"),
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
satisfies(NETWORK_PEER_ADDRESS, k -> k.isInstanceOf(String.class)),
satisfies(NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_ADDRESS,
k -> k.isInstanceOf(String.class)),
satisfies(
NetworkAttributes.NETWORK_PEER_PORT,
k -> k.isInstanceOf(Long.class)),
satisfies(
NetworkAttributes.NETWORK_TYPE,
NETWORK_TYPE,
k ->
k.satisfiesAnyOf(
val -> assertThat(val).isNull(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0;

import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PROTOCOL_VERSION;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.semconv.NetworkAttributes;
import java.net.URI;
import java.time.Duration;
import java.util.HashSet;
Expand Down Expand Up @@ -40,7 +41,7 @@ protected Set<AttributeKey<?>> getHttpAttributes(URI uri) {
|| "https://192.0.2.1/".equals(uri.toString())
|| uri.toString().contains("/read-timeout")
|| uri.toString().contains("/circular-redirect")) {
attributes.remove(NetworkAttributes.NETWORK_PROTOCOL_VERSION);
attributes.remove(NETWORK_PROTOCOL_VERSION);
}
return attributes;
}
Expand Down
Loading
Loading