diff --git a/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/build.gradle.kts b/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/build.gradle.kts index 1a1cca49c0aa..42cd0bd1467c 100644 --- a/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/build.gradle.kts +++ b/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/build.gradle.kts @@ -6,7 +6,7 @@ muzzle { pass { group.set("co.elastic.clients") module.set("elasticsearch-java") - versions.set("[7.16,)") + versions.set("[7.16,8.10)") // 8.10+ has native, on-by-default opentelemetry instrumentation assertInverse.set(true) } } @@ -23,6 +23,7 @@ dependencies { testImplementation("com.fasterxml.jackson.core:jackson-databind:2.14.2") testImplementation("org.testcontainers:elasticsearch") + // 8.10+ has native, on-by-default opentelemetry instrumentation latestDepTestLibrary("co.elastic.clients:elasticsearch-java:8.0.+") } diff --git a/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchApiClientInstrumentationModule.java b/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchApiClientInstrumentationModule.java index 31ab3e3b84b5..834be5b9e584 100644 --- a/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchApiClientInstrumentationModule.java +++ b/instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchApiClientInstrumentationModule.java @@ -5,12 +5,15 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.apiclient; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static java.util.Arrays.asList; +import static net.bytebuddy.matcher.ElementMatchers.not; import com.google.auto.service.AutoService; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import java.util.List; +import net.bytebuddy.matcher.ElementMatcher; @AutoService(InstrumentationModule.class) public class ElasticsearchApiClientInstrumentationModule extends InstrumentationModule { @@ -18,6 +21,15 @@ public ElasticsearchApiClientInstrumentationModule() { super("elasticsearch-api-client-7.16", "elasticsearch"); } + @Override + public ElementMatcher.Junction classLoaderMatcher() { + // Since Elasticsearch client version 8.10, the ES client comes with a native OTel + // instrumentation + // that introduced the class `co.elastic.clients.transport.instrumentation.Instrumentation`. + // Disabling agent instrumentation for those cases. + return not(hasClassesNamed("co.elastic.clients.transport.instrumentation.Instrumentation")); + } + @Override public List typeInstrumentations() { return asList( diff --git a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7InstrumentationModule.java b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7InstrumentationModule.java index 81001ea209e0..2546a5cac39b 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7InstrumentationModule.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7InstrumentationModule.java @@ -22,7 +22,7 @@ public ElasticsearchRest7InstrumentationModule() { @Override public ElementMatcher.Junction classLoaderMatcher() { - // class introduced in 7.0.0 + // Class `org.elasticsearch.client.RestClient$InternalRequest` introduced in 7.0.0. return hasClassesNamed("org.elasticsearch.client.RestClient$InternalRequest"); }