diff --git a/instrumentation/influxdb-2.4/javaagent/build.gradle.kts b/instrumentation/influxdb-2.4/javaagent/build.gradle.kts index d6a74c455b..ab93583d3e 100644 --- a/instrumentation/influxdb-2.4/javaagent/build.gradle.kts +++ b/instrumentation/influxdb-2.4/javaagent/build.gradle.kts @@ -17,6 +17,8 @@ dependencies { compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") + testInstrumentation(project(":instrumentation:okhttp:okhttp-3.0:javaagent")) + // we use methods that weren't present before 2.14 in tests testLibrary("org.influxdb:influxdb-java:2.14") } @@ -44,3 +46,9 @@ tasks { } } } + +tasks.withType().configureEach { + // we disable the okhttp instrumentation, so we don't need to assert on the okhttp spans + // from the okhttp instrumentation we need OkHttp3IgnoredTypesConfigurer to fix context leaks + jvmArgs("-Dotel.instrumentation.okhttp.enabled=false") +} diff --git a/instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java b/instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java index a2d209f1b4..c73bf34858 100644 --- a/instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java +++ b/instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java @@ -19,11 +19,10 @@ final class InfluxDbAttributesGetter implements DbClientAttributesGetter trace.hasSpansSatisfyingExactly( span -> - span.hasName("write " + dbName) + span.hasName("WRITE " + dbName) .hasKind(SpanKind.CLIENT) - .hasAttributesSatisfying(attributeAssertions("write", "write", dbName))), + .hasAttributesSatisfying(attributeAssertions(null, "WRITE", dbName))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -131,10 +126,7 @@ class InfluxDbClientTest { span.hasName("DROP DATABASE " + dbName) .hasKind(SpanKind.CLIENT) .hasAttributesSatisfying( - attributeAssertions( - String.format(DELETE_DATABASE_STATEMENT, dbName), - "DROP DATABASE", - dbName)))); + attributeAssertions(null, "DROP DATABASE", dbName)))); } @Test @@ -279,10 +271,10 @@ class InfluxDbClientTest { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("write " + databaseName) + span.hasName("WRITE " + databaseName) .hasKind(SpanKind.CLIENT) .hasAttributesSatisfying( - attributeAssertions("write", "write", databaseName)))); + attributeAssertions(null, "WRITE", databaseName)))); } @Test @@ -297,10 +289,10 @@ class InfluxDbClientTest { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("write " + databaseName) + span.hasName("WRITE " + databaseName) .hasKind(SpanKind.CLIENT) .hasAttributesSatisfying( - attributeAssertions("write", "write", databaseName)))); + attributeAssertions(null, "WRITE", databaseName)))); } @Test @@ -316,19 +308,24 @@ class InfluxDbClientTest { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("write") + span.hasName("WRITE") .hasKind(SpanKind.CLIENT) - .hasAttributesSatisfying(attributeAssertions("write", "write", null)))); + .hasAttributesSatisfying(attributeAssertions(null, "WRITE", null)))); } private static List attributeAssertions( String statement, String operation, String databaseName) { - return asList( - equalTo(DbIncubatingAttributes.DB_SYSTEM, "influxdb"), - equalTo(DbIncubatingAttributes.DB_NAME, databaseName), - equalTo(ServerAttributes.SERVER_ADDRESS, host), - equalTo(ServerAttributes.SERVER_PORT, port), - equalTo(DbIncubatingAttributes.DB_STATEMENT, statement), - equalTo(DbIncubatingAttributes.DB_OPERATION, operation)); + List result = new ArrayList<>(); + result.addAll( + asList( + equalTo(DbIncubatingAttributes.DB_SYSTEM, "influxdb"), + equalTo(DbIncubatingAttributes.DB_NAME, databaseName), + equalTo(ServerAttributes.SERVER_ADDRESS, host), + equalTo(ServerAttributes.SERVER_PORT, port), + equalTo(DbIncubatingAttributes.DB_OPERATION, operation))); + if (statement != null) { + result.add(equalTo(DbIncubatingAttributes.DB_STATEMENT, statement)); + } + return result; } } diff --git a/instrumentation/influxdb-2.4/javaagent/src/test24/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbClient24Test.java b/instrumentation/influxdb-2.4/javaagent/src/test24/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbClient24Test.java index faed6afea6..3cd3315255 100644 --- a/instrumentation/influxdb-2.4/javaagent/src/test24/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbClient24Test.java +++ b/instrumentation/influxdb-2.4/javaagent/src/test24/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbClient24Test.java @@ -5,8 +5,6 @@ package io.opentelemetry.javaagent.instrumentation.influxdb.v2_4; -import static io.opentelemetry.javaagent.instrumentation.influxdb.v2_4.InfluxDbConstants.CREATE_DATABASE_STATEMENT_NEW; -import static io.opentelemetry.javaagent.instrumentation.influxdb.v2_4.InfluxDbConstants.DELETE_DATABASE_STATEMENT; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; @@ -17,6 +15,7 @@ import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; import io.opentelemetry.semconv.ServerAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import org.influxdb.InfluxDB; @@ -101,16 +100,13 @@ class InfluxDbClient24Test { span.hasName("CREATE DATABASE " + dbName) .hasKind(SpanKind.CLIENT) .hasAttributesSatisfying( - attributeAssertions( - String.format(CREATE_DATABASE_STATEMENT_NEW, dbName), - "CREATE DATABASE", - dbName))), + attributeAssertions(null, "CREATE DATABASE", dbName))), trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("write " + dbName) + span.hasName("WRITE " + dbName) .hasKind(SpanKind.CLIENT) - .hasAttributesSatisfying(attributeAssertions("write", "write", dbName))), + .hasAttributesSatisfying(attributeAssertions(null, "WRITE", dbName))), trace -> trace.hasSpansSatisfyingExactly( span -> @@ -124,10 +120,7 @@ class InfluxDbClient24Test { span.hasName("DROP DATABASE " + dbName) .hasKind(SpanKind.CLIENT) .hasAttributesSatisfying( - attributeAssertions( - String.format(DELETE_DATABASE_STATEMENT, dbName), - "DROP DATABASE", - dbName)))); + attributeAssertions(null, "DROP DATABASE", dbName)))); } @Test @@ -150,12 +143,17 @@ class InfluxDbClient24Test { private static List attributeAssertions( String statement, String operation, String databaseName) { - return asList( - equalTo(DbIncubatingAttributes.DB_SYSTEM, "influxdb"), - equalTo(DbIncubatingAttributes.DB_NAME, databaseName), - equalTo(ServerAttributes.SERVER_ADDRESS, host), - equalTo(ServerAttributes.SERVER_PORT, port), - equalTo(DbIncubatingAttributes.DB_STATEMENT, statement), - equalTo(DbIncubatingAttributes.DB_OPERATION, operation)); + List result = new ArrayList<>(); + result.addAll( + asList( + equalTo(DbIncubatingAttributes.DB_SYSTEM, "influxdb"), + equalTo(DbIncubatingAttributes.DB_NAME, databaseName), + equalTo(ServerAttributes.SERVER_ADDRESS, host), + equalTo(ServerAttributes.SERVER_PORT, port), + equalTo(DbIncubatingAttributes.DB_OPERATION, operation))); + if (statement != null) { + result.add(equalTo(DbIncubatingAttributes.DB_STATEMENT, statement)); + } + return result; } }