Skip to content

Commit

Permalink
Disable Elasticsearch instrumentation for ES clients 8.10+ (#9337)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Wert <[email protected]>
Co-authored-by: Lauri Tulmin <[email protected]>
Co-authored-by: Trask Stalnaker <[email protected]>
Co-authored-by: Lauri Tulmin <[email protected]>
  • Loading branch information
4 people authored Sep 12, 2023
1 parent 1cb583a commit dc523cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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.+")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,31 @@

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 {
public ElasticsearchApiClientInstrumentationModule() {
super("elasticsearch-api-client-7.16", "elasticsearch");
}

@Override
public ElementMatcher.Junction<ClassLoader> 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<TypeInstrumentation> typeInstrumentations() {
return asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ElasticsearchRest7InstrumentationModule() {

@Override
public ElementMatcher.Junction<ClassLoader> 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");
}

Expand Down

0 comments on commit dc523cf

Please sign in to comment.