Skip to content

Commit

Permalink
Conditionally check network.type
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Nov 10, 2024
1 parent 65c3696 commit 6414eba
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
Expand Down Expand Up @@ -102,7 +103,7 @@ void syncTest(Parameter parameter) {
.hasKind(SpanKind.CLIENT)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand All @@ -116,7 +117,7 @@ void syncTest(Parameter parameter) {
.hasKind(SpanKind.CLIENT)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand All @@ -135,7 +136,7 @@ void syncTest(Parameter parameter) {
.hasKind(SpanKind.CLIENT)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand Down Expand Up @@ -174,7 +175,7 @@ void asyncTest(Parameter parameter) {
.hasKind(SpanKind.CLIENT)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand All @@ -189,7 +190,7 @@ void asyncTest(Parameter parameter) {
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand All @@ -213,7 +214,7 @@ void asyncTest(Parameter parameter) {
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.cassandra.v4.common;

import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
Expand Down Expand Up @@ -104,10 +105,15 @@ void syncTest(Parameter parameter) {
.hasAttributesSatisfyingExactly(
satisfies(
NETWORK_TYPE,
val ->
val -> {
if (emitStableDatabaseSemconv()) {
val.isNull();
} else {
val.satisfiesAnyOf(
v -> assertThat(v).isEqualTo("ipv4"),
v -> assertThat(v).isEqualTo("ipv6"))),
v -> assertThat(v).isEqualTo("ipv6"));
}
}),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand Down Expand Up @@ -158,10 +164,15 @@ void asyncTest(Parameter parameter) throws Exception {
.hasAttributesSatisfyingExactly(
satisfies(
NETWORK_TYPE,
val ->
val -> {
if (emitStableDatabaseSemconv()) {
val.isNull();
} else {
val.satisfiesAnyOf(
v -> assertThat(v).isEqualTo("ipv4"),
v -> assertThat(v).isEqualTo("ipv6"))),
v -> assertThat(v).isEqualTo("ipv6"));
}
}),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.testing.cassandra.v4_4;

import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
Expand Down Expand Up @@ -64,10 +65,15 @@ void reactiveTest(Parameter parameter) {
.hasAttributesSatisfyingExactly(
satisfies(
NETWORK_TYPE,
val ->
val -> {
if (emitStableDatabaseSemconv()) {
val.isNull();
} else {
val.satisfiesAnyOf(
v -> assertThat(v).isEqualTo("ipv4"),
v -> assertThat(v).isEqualTo("ipv6"))),
v -> assertThat(v).isEqualTo("ipv6"));
}
}),
equalTo(SERVER_ADDRESS, cassandraHost),
equalTo(SERVER_PORT, cassandraPort),
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING;

import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.AbstractElasticsearchTransportClientTest;
import java.io.File;
import java.util.Collections;
Expand Down Expand Up @@ -111,6 +112,6 @@ protected int getPort() {

@Override
protected boolean hasNetworkType() {
return true;
return SemconvStability.emitOldDatabaseSemconv();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.jedis.v3_0;

import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
Expand Down Expand Up @@ -85,7 +86,7 @@ void setCommand() {
equalTo(maybeStable(DB_OPERATION), "SET"),
equalTo(SERVER_ADDRESS, host),
equalTo(SERVER_PORT, port),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_ADDRESS, ip),
satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))));
}
Expand All @@ -109,7 +110,7 @@ void getCommand() {
equalTo(maybeStable(DB_OPERATION), "SET"),
equalTo(SERVER_ADDRESS, host),
equalTo(SERVER_PORT, port),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_ADDRESS, ip),
satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))),
trace ->
Expand All @@ -123,7 +124,7 @@ void getCommand() {
equalTo(maybeStable(DB_OPERATION), "GET"),
equalTo(SERVER_ADDRESS, host),
equalTo(SERVER_PORT, port),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_ADDRESS, ip),
satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))));
}
Expand All @@ -147,7 +148,7 @@ void commandWithNoArguments() {
equalTo(maybeStable(DB_OPERATION), "SET"),
equalTo(SERVER_ADDRESS, host),
equalTo(SERVER_PORT, port),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_ADDRESS, ip),
satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))),
trace ->
Expand All @@ -161,7 +162,7 @@ void commandWithNoArguments() {
equalTo(maybeStable(DB_OPERATION), "RANDOMKEY"),
equalTo(SERVER_ADDRESS, host),
equalTo(SERVER_PORT, port),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_ADDRESS, ip),
satisfies(NETWORK_PEER_PORT, AbstractLongAssert::isNotNegative))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.jedis.v4_0;

import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
Expand Down Expand Up @@ -76,7 +77,7 @@ void setCommand() {
equalTo(DB_SYSTEM, "redis"),
equalTo(maybeStable(DB_STATEMENT), "SET foo ?"),
equalTo(maybeStable(DB_OPERATION), "SET"),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_PORT, port),
equalTo(NETWORK_PEER_ADDRESS, ip))));
}
Expand All @@ -98,7 +99,7 @@ void getCommand() {
equalTo(DB_SYSTEM, "redis"),
equalTo(maybeStable(DB_STATEMENT), "SET foo ?"),
equalTo(maybeStable(DB_OPERATION), "SET"),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_PORT, port),
equalTo(NETWORK_PEER_ADDRESS, ip))),
trace ->
Expand All @@ -110,7 +111,7 @@ void getCommand() {
equalTo(DB_SYSTEM, "redis"),
equalTo(maybeStable(DB_STATEMENT), "GET foo"),
equalTo(maybeStable(DB_OPERATION), "GET"),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_PORT, port),
equalTo(NETWORK_PEER_ADDRESS, ip))));
}
Expand All @@ -132,7 +133,7 @@ void commandWithNoArguments() {
equalTo(DB_SYSTEM, "redis"),
equalTo(maybeStable(DB_STATEMENT), "SET foo ?"),
equalTo(maybeStable(DB_OPERATION), "SET"),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_PORT, port),
equalTo(NETWORK_PEER_ADDRESS, ip))),
trace ->
Expand All @@ -144,7 +145,7 @@ void commandWithNoArguments() {
equalTo(DB_SYSTEM, "redis"),
equalTo(maybeStable(DB_STATEMENT), "RANDOMKEY"),
equalTo(maybeStable(DB_OPERATION), "RANDOMKEY"),
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_PORT, port),
equalTo(NETWORK_PEER_ADDRESS, ip))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.lettuce.v5_1;

import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableDatabaseSemconv;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
Expand Down Expand Up @@ -59,7 +60,8 @@ void testAsyncSubscriberWithSpecificThreadPool() {
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
addExtraAttributes(
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(
NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_ADDRESS, ip),
equalTo(NETWORK_PEER_PORT, port),
equalTo(SERVER_ADDRESS, host),
Expand All @@ -75,7 +77,8 @@ void testAsyncSubscriberWithSpecificThreadPool() {
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
addExtraAttributes(
equalTo(NETWORK_TYPE, "ipv4"),
equalTo(
NETWORK_TYPE, emitStableDatabaseSemconv() ? null : "ipv4"),
equalTo(NETWORK_PEER_ADDRESS, ip),
equalTo(NETWORK_PEER_PORT, port),
equalTo(SERVER_ADDRESS, host),
Expand Down
Loading

0 comments on commit 6414eba

Please sign in to comment.