From 293df5f244eeb98c512c46770c6491b581f79775 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Thu, 6 Mar 2025 17:07:55 +0200 Subject: [PATCH 1/2] Add debug logging to flaky apache async client tests --- .../javaagent/build.gradle.kts | 1 + ...ApacheHttpClientInstrumentationModule.java | 10 +++++ .../v5_0/IoReactorInstrumentation.java | 41 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorInstrumentation.java diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts index 49122b19ca14..a06bd1a45320 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts @@ -17,5 +17,6 @@ dependencies { tasks { withType().configureEach { systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) + systemProperty("otel.instrumentation.pache-httpclient-5.debug", "true") } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java index 0e478a395f1c..4dd4b06e3a56 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0; import com.google.auto.service.AutoService; +import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import java.util.Arrays; @@ -20,6 +21,15 @@ public ApacheHttpClientInstrumentationModule() { @Override public List typeInstrumentations() { + boolean debug = + AgentInstrumentationConfig.get() + .getBoolean("otel.instrumentation.pache-httpclient-5.debug", false); + if (debug) { + return Arrays.asList( + new ApacheHttpClientInstrumentation(), + new ApacheHttpAsyncClientInstrumentation(), + new IoReactorInstrumentation()); + } return Arrays.asList( new ApacheHttpClientInstrumentation(), new ApacheHttpAsyncClientInstrumentation()); } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorInstrumentation.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorInstrumentation.java new file mode 100644 index 000000000000..ae0106e23f8a --- /dev/null +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorInstrumentation.java @@ -0,0 +1,41 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0; + +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; + +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class IoReactorInstrumentation implements TypeInstrumentation { + + @Override + public ElementMatcher typeMatcher() { + return implementsInterface(named("org.apache.hc.core5.reactor.IOReactor")); + } + + @Override + public void transform(TypeTransformer transformer) { + transformer.applyAdviceToMethod( + namedOneOf("close", "initiateShutdown"), this.getClass().getName() + "$CloseAdvice"); + } + + @SuppressWarnings("unused") + public static class CloseAdvice { + + @SuppressWarnings("SystemOut") + @Advice.OnMethodEnter(suppress = Throwable.class) + public static void methodEnter(@Advice.This Object instance) { + System.err.println("closing i/o reactor " + instance); + new Exception().printStackTrace(); + } + } +} From f633d82a6b64dd6877bce073e8789dd1f113caca Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Thu, 6 Mar 2025 19:35:54 +0200 Subject: [PATCH 2/2] address review comments --- .../apache-httpclient-5.0/javaagent/build.gradle.kts | 2 +- .../v5_0/ApacheHttpClientInstrumentationModule.java | 4 ++-- ...nstrumentation.java => IoReactorDebugInstrumentation.java} | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/{IoReactorInstrumentation.java => IoReactorDebugInstrumentation.java} (94%) diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts index a06bd1a45320..8056ecce006f 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/build.gradle.kts @@ -17,6 +17,6 @@ dependencies { tasks { withType().configureEach { systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) - systemProperty("otel.instrumentation.pache-httpclient-5.debug", "true") + systemProperty("otel.instrumentation.apache-httpclient-5.debug", "true") } } diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java index 4dd4b06e3a56..83ee1c681486 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentationModule.java @@ -23,12 +23,12 @@ public ApacheHttpClientInstrumentationModule() { public List typeInstrumentations() { boolean debug = AgentInstrumentationConfig.get() - .getBoolean("otel.instrumentation.pache-httpclient-5.debug", false); + .getBoolean("otel.instrumentation.apache-httpclient-5.debug", false); if (debug) { return Arrays.asList( new ApacheHttpClientInstrumentation(), new ApacheHttpAsyncClientInstrumentation(), - new IoReactorInstrumentation()); + new IoReactorDebugInstrumentation()); } return Arrays.asList( new ApacheHttpClientInstrumentation(), new ApacheHttpAsyncClientInstrumentation()); diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorInstrumentation.java b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorDebugInstrumentation.java similarity index 94% rename from instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorInstrumentation.java rename to instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorDebugInstrumentation.java index ae0106e23f8a..53a9f9c01c87 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorInstrumentation.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/IoReactorDebugInstrumentation.java @@ -15,7 +15,7 @@ import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; -public class IoReactorInstrumentation implements TypeInstrumentation { +public class IoReactorDebugInstrumentation implements TypeInstrumentation { @Override public ElementMatcher typeMatcher() {