From 0811d596bc4c725501c016755a61a09381e6cf7f Mon Sep 17 00:00:00 2001 From: Alexander Wert Date: Tue, 29 Aug 2023 14:24:07 +0200 Subject: [PATCH 1/4] Disable ES client instrumentation for ES client versions with native instrumentation Signed-off-by: Alexander Wert --- .../ElasticsearchRestClientInstrumentation.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentation.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentation.java index 4c54b64108..303b0f82ba 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentation.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentation.java @@ -21,6 +21,10 @@ import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Tracer; +import net.bytebuddy.matcher.ElementMatcher; + +import static co.elastic.apm.agent.sdk.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; +import static net.bytebuddy.matcher.ElementMatchers.not; import java.util.Collection; import java.util.Collections; @@ -35,4 +39,10 @@ public Collection getInstrumentationGroupNames() { return Collections.singleton("elasticsearch-restclient"); } + @Override + public ElementMatcher.Junction getClassLoaderMatcher() { + // ensure only ES client versions without native instrumentation are instrumented + return not(classLoaderCanLoadClass("co.elastic.clients.transport.instrumentation.Instrumentation")); + } + } From f27141be416beb25317dac89de3fbcaa45785a26 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Tue, 5 Sep 2023 15:52:15 +0200 Subject: [PATCH 2/4] Prevent es client dependencies from being updated via dependabot --- .github/dependabot.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1e4c5b1748..65525c4e40 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -33,8 +33,6 @@ updates: - dependency-name: "com.datastax.oss:java-driver-core" - dependency-name: "io.micrometer:*" - dependency-name: "redis.clients:*" - - dependency-name: "org.elasticsearch.client:*" - - dependency-name: "co.elastic.clients:*" - dependency-name: "io.vertx:*" - dependency-name: "org.apache.logging.log4j:*" - dependency-name: "org.springframework.boot:*" From a219c62448395917d5fe8456057df845a46d2918 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Wed, 6 Sep 2023 09:08:44 +0200 Subject: [PATCH 3/4] Update comment to include version --- .../ElasticsearchRestClientInstrumentation.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentation.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentation.java index 303b0f82ba..d32a0eca74 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentation.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentation.java @@ -23,12 +23,12 @@ import co.elastic.apm.agent.tracer.Tracer; import net.bytebuddy.matcher.ElementMatcher; -import static co.elastic.apm.agent.sdk.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; -import static net.bytebuddy.matcher.ElementMatchers.not; - import java.util.Collection; import java.util.Collections; +import static co.elastic.apm.agent.sdk.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; +import static net.bytebuddy.matcher.ElementMatchers.not; + public abstract class ElasticsearchRestClientInstrumentation extends ElasticApmInstrumentation { @@ -41,7 +41,7 @@ public Collection getInstrumentationGroupNames() { @Override public ElementMatcher.Junction getClassLoaderMatcher() { - // ensure only ES client versions without native instrumentation are instrumented + // ensure only ES client versions without native instrumentation are instrumented (8.9 and older) return not(classLoaderCanLoadClass("co.elastic.clients.transport.instrumentation.Instrumentation")); } From a9ccea15aa7cc062e522245d676f459dc2e3b296 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Wed, 6 Sep 2023 09:10:56 +0200 Subject: [PATCH 4/4] Added changelog --- CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index cb9f2eb182..6062e6eebf 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -42,6 +42,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes: ===== Features * Add support for Elasticsearch client 8.9 - {pull}3283[#3283] * Added `baggage_to_attach` config option to allow automatic lifting of baggage into transaction, span and error attributes - {pull}3288[#3288], {pull}3289[#3289] +* Exclude elasticsearch 8.10 and newer clients from instrumentation because they natively support OpenTelemetry - {pull}3303[#3303] [[release-notes-1.x]] === Java Agent version 1.x