From f22bd61c9d3ad3a586ea6f71e0b4c73b68fe87f6 Mon Sep 17 00:00:00 2001 From: "elastic-observability-automation[bot]" <180520183+elastic-observability-automation[bot]@users.noreply.github.com> Date: Tue, 25 Nov 2025 06:02:46 +0000 Subject: [PATCH 01/23] chore: Update upstream OpenTelemetry agent version and related depend... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... encies Made with ❤️️ by updatecli --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4757e535..2c88df15 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ opentelemetryProto = "1.3.2-alpha" # otel agent, we rely on the '*-alpha' and get the non-alpha dependencies transitively # updated from upstream agent with gradle/update-upstream.sh -opentelemetryJavaagentAlpha = "2.21.0-alpha" +opentelemetryJavaagentAlpha = "2.22.0-alpha" # otel contrib # updated from upstream agent with gradle/update-upstream.sh From 6292802f758978e3a78f8fbcc9ed52c737bd9ed4 Mon Sep 17 00:00:00 2001 From: jackshirazi Date: Tue, 25 Nov 2025 12:26:05 +0000 Subject: [PATCH 02/23] Update libs.versions.toml --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2c88df15..169e4ce5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ opentelemetryJavaagentAlpha = "2.22.0-alpha" # otel contrib # updated from upstream agent with gradle/update-upstream.sh -opentelemetryContribAlpha = "1.51.0-alpha" +opentelemetryContribAlpha = "1.52.0-alpha" # otel semconv # updated from upstream agent with gradle/update-upstream.sh From 24586aa0fe35fbef98ed27098da572ddb0cb9b4f Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Tue, 25 Nov 2025 17:56:14 +0000 Subject: [PATCH 03/23] show checkLogConfigPresent values --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index fe4b87da..f41de475 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -56,7 +56,9 @@ public static void teardown() throws IOException { @Test public void checkLogConfigPresent() throws IOException { String output = executeCommand(createTestTargetCommand(true), 20); + System.out.println("------------ checkLogConfigPresent: 1 "+output); for (String identifyingString : identifyingStrings) { + System.out.println("------------ checkLogConfigPresent: 2 "+identifyingStrings); assertThat(output).contains(identifyingString); } } From b7138105e7c728c78f95c054767916175acf3fea Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Tue, 25 Nov 2025 19:35:53 +0000 Subject: [PATCH 04/23] spotless --- .../elastic/otel/config/ConfigLoggingAgentListenerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index f41de475..c03d5640 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -56,9 +56,9 @@ public static void teardown() throws IOException { @Test public void checkLogConfigPresent() throws IOException { String output = executeCommand(createTestTargetCommand(true), 20); - System.out.println("------------ checkLogConfigPresent: 1 "+output); + System.out.println("------------ checkLogConfigPresent: 1 " + output); for (String identifyingString : identifyingStrings) { - System.out.println("------------ checkLogConfigPresent: 2 "+identifyingStrings); + System.out.println("------------ checkLogConfigPresent: 2 " + identifyingStrings); assertThat(output).contains(identifyingString); } } From a3154ec3ed70d465cd4691134a732bbdc4f23eea Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Tue, 25 Nov 2025 21:19:00 +0000 Subject: [PATCH 05/23] turn off CDS for the test --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index c03d5640..9b1acb80 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -56,9 +56,7 @@ public static void teardown() throws IOException { @Test public void checkLogConfigPresent() throws IOException { String output = executeCommand(createTestTargetCommand(true), 20); - System.out.println("------------ checkLogConfigPresent: 1 " + output); for (String identifyingString : identifyingStrings) { - System.out.println("------------ checkLogConfigPresent: 2 " + identifyingStrings); assertThat(output).contains(identifyingString); } } @@ -75,6 +73,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio List command = new ArrayList<>(); command.add("java"); command.add("-Xmx32m"); + command.add("-Xshare:off"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From b63b4333879f8883b62f9218850de0439eb913b6 Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Tue, 25 Nov 2025 22:09:54 +0000 Subject: [PATCH 06/23] turn off CDS archive for the test --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 9b1acb80..0600a48e 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -74,6 +74,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio command.add("java"); command.add("-Xmx32m"); command.add("-Xshare:off"); + command.add("-XX:SharedArchiveFile=none"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From 6b33632d4cdcee408aaae91901179915f96f8c7d Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 00:03:30 +0000 Subject: [PATCH 07/23] turn off CDS for the test --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 0600a48e..f972e098 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -75,6 +75,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio command.add("-Xmx32m"); command.add("-Xshare:off"); command.add("-XX:SharedArchiveFile=none"); + command.add("-XX:-UseSharedSpaces"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From ebd40c096752434a3b8a757c3b7acf427eba3b6c Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 12:58:59 +0000 Subject: [PATCH 08/23] change to a compiled class --- .../ConfigLoggingAgentListenerTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index f972e098..9cb60bbb 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -28,6 +28,8 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -46,11 +48,24 @@ public class ConfigLoggingAgentListenerTest { public static void setup() throws IOException { agentJarFile = getAgentJarFile(); testTargetClass = createTestTarget(); + compileTestTarget(testTargetClass); + } + + private static void compileTestTarget(File sourceFile) { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + if (compiler == null) { + throw new IllegalStateException("No Java compiler available"); + } + int result = compiler.run(null, null, null, sourceFile.getAbsolutePath()); + if (result != 0) { + throw new IllegalStateException("Compilation failed"); + } } @AfterAll public static void teardown() throws IOException { testTargetClass.delete(); + new File(testTargetClass.getParent(), TARGET_CLASS_NAME + ".class").delete(); } @Test @@ -73,15 +88,14 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio List command = new ArrayList<>(); command.add("java"); command.add("-Xmx32m"); - command.add("-Xshare:off"); - command.add("-XX:SharedArchiveFile=none"); - command.add("-XX:-UseSharedSpaces"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { command.add("-D" + ConfigLoggingAgentListener.LOG_THE_CONFIG + "=false"); } - command.add(testTargetClass.getAbsolutePath()); + command.add("-cp"); + command.add(testTargetClass.getParent()); + command.add(TARGET_CLASS_NAME); return command; } From 9c3fb059d97e02f116e8a8c26a29f7f752ff9dc9 Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 13:40:45 +0000 Subject: [PATCH 09/23] temp disable autoservice --- .../co/elastic/otel/config/ConfigLoggingAgentListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom/src/main/java/co/elastic/otel/config/ConfigLoggingAgentListener.java b/custom/src/main/java/co/elastic/otel/config/ConfigLoggingAgentListener.java index a047869d..ad7fe6b9 100644 --- a/custom/src/main/java/co/elastic/otel/config/ConfigLoggingAgentListener.java +++ b/custom/src/main/java/co/elastic/otel/config/ConfigLoggingAgentListener.java @@ -19,12 +19,12 @@ package co.elastic.otel.config; import co.elastic.otel.compositesampling.DynamicCompositeParentBasedTraceIdRatioBasedSampler; -import com.google.auto.service.AutoService; +// import com.google.auto.service.AutoService; import io.opentelemetry.javaagent.extension.AgentListener; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; import java.util.logging.Logger; -@AutoService(AgentListener.class) +// @AutoService(AgentListener.class) public class ConfigLoggingAgentListener implements AgentListener { public static final String LOG_THE_CONFIG = "elastic.otel.java.experimental.configuration.logging.enabled"; From 9b05c3e899bc194a9368ba019d9ea2d42577de0e Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 14:21:52 +0000 Subject: [PATCH 10/23] disable method handle customization --- .../co/elastic/otel/config/ConfigLoggingAgentListener.java | 4 ++-- .../elastic/otel/config/ConfigLoggingAgentListenerTest.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/custom/src/main/java/co/elastic/otel/config/ConfigLoggingAgentListener.java b/custom/src/main/java/co/elastic/otel/config/ConfigLoggingAgentListener.java index ad7fe6b9..a047869d 100644 --- a/custom/src/main/java/co/elastic/otel/config/ConfigLoggingAgentListener.java +++ b/custom/src/main/java/co/elastic/otel/config/ConfigLoggingAgentListener.java @@ -19,12 +19,12 @@ package co.elastic.otel.config; import co.elastic.otel.compositesampling.DynamicCompositeParentBasedTraceIdRatioBasedSampler; -// import com.google.auto.service.AutoService; +import com.google.auto.service.AutoService; import io.opentelemetry.javaagent.extension.AgentListener; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; import java.util.logging.Logger; -// @AutoService(AgentListener.class) +@AutoService(AgentListener.class) public class ConfigLoggingAgentListener implements AgentListener { public static final String LOG_THE_CONFIG = "elastic.otel.java.experimental.configuration.logging.enabled"; diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 9cb60bbb..a5ab1641 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -88,6 +88,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio List command = new ArrayList<>(); command.add("java"); command.add("-Xmx32m"); + command.add("-Djava.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD=10000"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From 2c6c620b43a8dbd5ef1a88e0b47d664b3cd682ac Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 14:44:17 +0000 Subject: [PATCH 11/23] disable method handle customization properly --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index a5ab1641..0c384921 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -88,7 +88,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio List command = new ArrayList<>(); command.add("java"); command.add("-Xmx32m"); - command.add("-Djava.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD=10000"); + command.add("-Djava.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD=-1"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From 40fbb2e4d823f8226b8eef1a8177aea1268e176a Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 15:10:19 +0000 Subject: [PATCH 12/23] make string concat avoid method handles --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 0c384921..236c1d52 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -89,6 +89,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio command.add("java"); command.add("-Xmx32m"); command.add("-Djava.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD=-1"); + command.add("-Djava.lang.invoke.stringConcat=BC_SB"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From a621d1db0e25d775310a0f77b3c9a802a29613a0 Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 15:20:19 +0000 Subject: [PATCH 13/23] spotless --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 236c1d52..72604e2e 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -89,7 +89,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio command.add("java"); command.add("-Xmx32m"); command.add("-Djava.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD=-1"); - command.add("-Djava.lang.invoke.stringConcat=BC_SB"); + command.add("-Djava.lang.invoke.stringConcat=BC_SB"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From cfc240f4da1c679124e29f89963c4b262d93818c Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 15:43:21 +0000 Subject: [PATCH 14/23] log to app --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 72604e2e..4e6b1a57 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -90,6 +90,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio command.add("-Xmx32m"); command.add("-Djava.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD=-1"); command.add("-Djava.lang.invoke.stringConcat=BC_SB"); + command.add("-Dotel.javaagent.logging=application"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From 3fb62a8fd916337cae2e92b1bf8d16e8194c65b0 Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 16:01:00 +0000 Subject: [PATCH 15/23] timeout --- .../elastic/otel/config/ConfigLoggingAgentListenerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 4e6b1a57..8ba8f890 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -70,7 +70,7 @@ public static void teardown() throws IOException { @Test public void checkLogConfigPresent() throws IOException { - String output = executeCommand(createTestTargetCommand(true), 20); + String output = executeCommand(createTestTargetCommand(true), 60); for (String identifyingString : identifyingStrings) { assertThat(output).contains(identifyingString); } @@ -78,7 +78,7 @@ public void checkLogConfigPresent() throws IOException { @Test public void checkLogConfigAbsent() throws IOException { - String output = executeCommand(createTestTargetCommand(false), 20); + String output = executeCommand(createTestTargetCommand(false), 60); for (String identifyingString : identifyingStrings) { assertThat(output).doesNotContain(identifyingString); } From e2923e967b945123ee5ef545fd49a823ac05ef24 Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 16:34:50 +0000 Subject: [PATCH 16/23] log to app at info level --- .../ConfigLoggingAgentListenerTest.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 8ba8f890..ed4e9918 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -36,6 +36,7 @@ public class ConfigLoggingAgentListenerTest { static final String TARGET_CLASS_NAME = "TempTest321"; + static final String LOGGING_PROPERTIES_FILE_NAME = "test_logging.properties"; static String[] identifyingStrings = { "ConfigLoggingAgentListener - AutoConfiguredOpenTelemetrySdk{", "tracerProvider=SdkTracerProvider" @@ -49,6 +50,22 @@ public static void setup() throws IOException { agentJarFile = getAgentJarFile(); testTargetClass = createTestTarget(); compileTestTarget(testTargetClass); + createLoggingPropertiesFile(); + } + + private static void createLoggingPropertiesFile() throws IOException { + File loggingPropertiesFile = + new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME); + loggingPropertiesFile.deleteOnExit(); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(loggingPropertiesFile))) { + writer.write("handlers=java.util.logging.ConsoleHandler\n"); + writer.write(".level=INFO\n"); + writer.write("java.util.logging.ConsoleHandler.level=INFO\n"); + writer.write( + "java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter\n"); + writer.write( + "java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s - %5$s%6$s%n\n"); + } } private static void compileTestTarget(File sourceFile) { @@ -66,6 +83,7 @@ private static void compileTestTarget(File sourceFile) { public static void teardown() throws IOException { testTargetClass.delete(); new File(testTargetClass.getParent(), TARGET_CLASS_NAME + ".class").delete(); + new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME).delete(); } @Test @@ -88,8 +106,10 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio List command = new ArrayList<>(); command.add("java"); command.add("-Xmx32m"); - command.add("-Djava.lang.invoke.MethodHandle.CUSTOMIZE_THRESHOLD=-1"); - command.add("-Djava.lang.invoke.stringConcat=BC_SB"); + command.add( + "-Djava.util.logging.config.file=" + + new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME) + .getAbsolutePath()); command.add("-Dotel.javaagent.logging=application"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option From 19649d98ff8698e8f2d330dc089f41c0fae29acc Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 18:22:09 +0000 Subject: [PATCH 17/23] log none --- .../ConfigLoggingAgentListenerTest.java | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index ed4e9918..9c00a937 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -36,7 +36,6 @@ public class ConfigLoggingAgentListenerTest { static final String TARGET_CLASS_NAME = "TempTest321"; - static final String LOGGING_PROPERTIES_FILE_NAME = "test_logging.properties"; static String[] identifyingStrings = { "ConfigLoggingAgentListener - AutoConfiguredOpenTelemetrySdk{", "tracerProvider=SdkTracerProvider" @@ -50,22 +49,6 @@ public static void setup() throws IOException { agentJarFile = getAgentJarFile(); testTargetClass = createTestTarget(); compileTestTarget(testTargetClass); - createLoggingPropertiesFile(); - } - - private static void createLoggingPropertiesFile() throws IOException { - File loggingPropertiesFile = - new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME); - loggingPropertiesFile.deleteOnExit(); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(loggingPropertiesFile))) { - writer.write("handlers=java.util.logging.ConsoleHandler\n"); - writer.write(".level=INFO\n"); - writer.write("java.util.logging.ConsoleHandler.level=INFO\n"); - writer.write( - "java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter\n"); - writer.write( - "java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s - %5$s%6$s%n\n"); - } } private static void compileTestTarget(File sourceFile) { @@ -83,7 +66,6 @@ private static void compileTestTarget(File sourceFile) { public static void teardown() throws IOException { testTargetClass.delete(); new File(testTargetClass.getParent(), TARGET_CLASS_NAME + ".class").delete(); - new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME).delete(); } @Test @@ -106,11 +88,7 @@ static List createTestTargetCommand(boolean logConfig) throws IOExceptio List command = new ArrayList<>(); command.add("java"); command.add("-Xmx32m"); - command.add( - "-Djava.util.logging.config.file=" - + new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME) - .getAbsolutePath()); - command.add("-Dotel.javaagent.logging=application"); + command.add("-Dotel.javaagent.logging=none"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { From 276d0630713779c62776f2dd52c50589d0db2c7e Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 20:07:09 +0000 Subject: [PATCH 18/23] log to app at info level --- .../ConfigLoggingAgentListenerTest.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 9c00a937..9f3de0e8 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -36,6 +36,7 @@ public class ConfigLoggingAgentListenerTest { static final String TARGET_CLASS_NAME = "TempTest321"; + static final String LOGGING_PROPERTIES_FILE_NAME = "test_logging.properties"; static String[] identifyingStrings = { "ConfigLoggingAgentListener - AutoConfiguredOpenTelemetrySdk{", "tracerProvider=SdkTracerProvider" @@ -49,6 +50,23 @@ public static void setup() throws IOException { agentJarFile = getAgentJarFile(); testTargetClass = createTestTarget(); compileTestTarget(testTargetClass); + createLoggingPropertiesFile(); + } + + private static void createLoggingPropertiesFile() throws IOException { + File loggingPropertiesFile = + new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME); + loggingPropertiesFile.deleteOnExit(); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(loggingPropertiesFile))) { + writer.write("handlers=java.util.logging.ConsoleHandler\n"); + writer.write(".level=INFO\n"); + writer.write("java.util.logging.ConsoleHandler.level=INFO\n"); + writer.write( + "java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter\n"); + // Avoid date/time in format to prevent ClassCircularityError with CLDR/Locale + writer.write( + "java.util.logging.SimpleFormatter.format=%4$s: %5$s%6$s%n\n"); + } } private static void compileTestTarget(File sourceFile) { @@ -66,6 +84,7 @@ private static void compileTestTarget(File sourceFile) { public static void teardown() throws IOException { testTargetClass.delete(); new File(testTargetClass.getParent(), TARGET_CLASS_NAME + ".class").delete(); + new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME).delete(); } @Test @@ -87,10 +106,11 @@ public void checkLogConfigAbsent() throws IOException { static List createTestTargetCommand(boolean logConfig) throws IOException { List command = new ArrayList<>(); command.add("java"); - command.add("-Xmx32m"); - command.add("-Dotel.javaagent.logging=none"); - command.add("-javaagent:" + agentJarFile); - // Only on false, ie test the 'true' default with no option + command.add("-Xmx32m"); + command.add("-Djava.util.logging.config.file=" + + new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME).getAbsolutePath()); + command.add("-Dotel.javaagent.logging=application"); + command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { command.add("-D" + ConfigLoggingAgentListener.LOG_THE_CONFIG + "=false"); } From a306abd11338306b737ee66c2fc56f37218fe8ed Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 22:42:51 +0000 Subject: [PATCH 19/23] back to app log and no debug --- .../ConfigLoggingAgentListenerTest.java | 54 ++++--------------- 1 file changed, 9 insertions(+), 45 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 9f3de0e8..1314f7e0 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -28,15 +28,12 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import javax.tools.JavaCompiler; -import javax.tools.ToolProvider; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; public class ConfigLoggingAgentListenerTest { static final String TARGET_CLASS_NAME = "TempTest321"; - static final String LOGGING_PROPERTIES_FILE_NAME = "test_logging.properties"; static String[] identifyingStrings = { "ConfigLoggingAgentListener - AutoConfiguredOpenTelemetrySdk{", "tracerProvider=SdkTracerProvider" @@ -49,47 +46,16 @@ public class ConfigLoggingAgentListenerTest { public static void setup() throws IOException { agentJarFile = getAgentJarFile(); testTargetClass = createTestTarget(); - compileTestTarget(testTargetClass); - createLoggingPropertiesFile(); - } - - private static void createLoggingPropertiesFile() throws IOException { - File loggingPropertiesFile = - new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME); - loggingPropertiesFile.deleteOnExit(); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(loggingPropertiesFile))) { - writer.write("handlers=java.util.logging.ConsoleHandler\n"); - writer.write(".level=INFO\n"); - writer.write("java.util.logging.ConsoleHandler.level=INFO\n"); - writer.write( - "java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter\n"); - // Avoid date/time in format to prevent ClassCircularityError with CLDR/Locale - writer.write( - "java.util.logging.SimpleFormatter.format=%4$s: %5$s%6$s%n\n"); - } - } - - private static void compileTestTarget(File sourceFile) { - JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); - if (compiler == null) { - throw new IllegalStateException("No Java compiler available"); - } - int result = compiler.run(null, null, null, sourceFile.getAbsolutePath()); - if (result != 0) { - throw new IllegalStateException("Compilation failed"); - } } @AfterAll public static void teardown() throws IOException { testTargetClass.delete(); - new File(testTargetClass.getParent(), TARGET_CLASS_NAME + ".class").delete(); - new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME).delete(); } @Test public void checkLogConfigPresent() throws IOException { - String output = executeCommand(createTestTargetCommand(true), 60); + String output = executeCommand(createTestTargetCommand(true), 20); for (String identifyingString : identifyingStrings) { assertThat(output).contains(identifyingString); } @@ -97,7 +63,7 @@ public void checkLogConfigPresent() throws IOException { @Test public void checkLogConfigAbsent() throws IOException { - String output = executeCommand(createTestTargetCommand(false), 60); + String output = executeCommand(createTestTargetCommand(false), 20); for (String identifyingString : identifyingStrings) { assertThat(output).doesNotContain(identifyingString); } @@ -106,17 +72,15 @@ public void checkLogConfigAbsent() throws IOException { static List createTestTargetCommand(boolean logConfig) throws IOException { List command = new ArrayList<>(); command.add("java"); - command.add("-Xmx32m"); - command.add("-Djava.util.logging.config.file=" - + new File(System.getProperty("java.io.tmpdir"), LOGGING_PROPERTIES_FILE_NAME).getAbsolutePath()); - command.add("-Dotel.javaagent.logging=application"); - command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option + command.add("-Xmx32m"); + command.add("-Dotel.javaagent.logging=application"); + command.add("-Dotel.javaagent.debug=false"); + command.add("-javaagent:" + agentJarFile); + // Only on false, ie test the 'true' default with no option if (!logConfig) { command.add("-D" + ConfigLoggingAgentListener.LOG_THE_CONFIG + "=false"); } - command.add("-cp"); - command.add(testTargetClass.getParent()); - command.add(TARGET_CLASS_NAME); + command.add(testTargetClass.getAbsolutePath()); return command; } @@ -198,4 +162,4 @@ private static void pauseSeconds(int seconds) { } catch (InterruptedException e) { } } -} +} \ No newline at end of file From 1f8947e78598e541d7b8bfd0386c59678bab508d Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Wed, 26 Nov 2025 22:52:37 +0000 Subject: [PATCH 20/23] spotless --- .../co/elastic/otel/config/ConfigLoggingAgentListenerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 1314f7e0..986752a5 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -162,4 +162,4 @@ private static void pauseSeconds(int seconds) { } catch (InterruptedException e) { } } -} \ No newline at end of file +} From f9d98b4470ce73c7ff64e2dae8ac6e2ad2c6766e Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Thu, 27 Nov 2025 14:57:18 +0000 Subject: [PATCH 21/23] change to compiled and filtered out debug config log --- .../ConfigLoggingAgentListenerTest.java | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java index 986752a5..907f2674 100644 --- a/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java +++ b/custom/src/test/java/co/elastic/otel/config/ConfigLoggingAgentListenerTest.java @@ -28,6 +28,8 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -41,21 +43,26 @@ public class ConfigLoggingAgentListenerTest { private static String agentJarFile; private static File testTargetClass; + private static File testTargetCompiledClass; @BeforeAll public static void setup() throws IOException { agentJarFile = getAgentJarFile(); testTargetClass = createTestTarget(); + compileTestTarget(testTargetClass); + testTargetCompiledClass = new File(testTargetClass.getParent(), TARGET_CLASS_NAME + ".class"); } @AfterAll public static void teardown() throws IOException { testTargetClass.delete(); + testTargetCompiledClass.delete(); } @Test public void checkLogConfigPresent() throws IOException { - String output = executeCommand(createTestTargetCommand(true), 20); + String output = + filterOutUpstreamDebugConfigLine(executeCommand(createTestTargetCommand(true), 120)); for (String identifyingString : identifyingStrings) { assertThat(output).contains(identifyingString); } @@ -63,27 +70,54 @@ public void checkLogConfigPresent() throws IOException { @Test public void checkLogConfigAbsent() throws IOException { - String output = executeCommand(createTestTargetCommand(false), 20); + String output = + filterOutUpstreamDebugConfigLine(executeCommand(createTestTargetCommand(false), 120)); for (String identifyingString : identifyingStrings) { assertThat(output).doesNotContain(identifyingString); } } + static String filterOutUpstreamDebugConfigLine(String line) { + // remove the debug level AutoConfiguredOpenTelemetrySdkBuilder output as this has the same + // content apart from being from AutoConfiguredOpenTelemetrySdkBuilder + if (line.contains( + "AutoConfiguredOpenTelemetrySdkBuilder - Global OpenTelemetry set to OpenTelemetrySdk")) { + return line.replaceFirst( + "[\r\n].*?AutoConfiguredOpenTelemetrySdkBuilder - Global OpenTelemetry set to OpenTelemetrySdk.*?[\r\n]", + ""); + } + return line; + } + static List createTestTargetCommand(boolean logConfig) throws IOException { List command = new ArrayList<>(); command.add("java"); command.add("-Xmx32m"); command.add("-Dotel.javaagent.logging=application"); command.add("-Dotel.javaagent.debug=false"); + command.add("-Dotel.service.name=ConfigLoggingAgentListenerTest:" + logConfig); + command.add("-Dotel.traces.exporter=none"); + command.add("-Dotel.resource.providers.aws.enabled=false"); + command.add("-Dotel.resource.providers.gcp.enabled=false"); + command.add("-Dotel.resource.providers.azure.enabled=false"); command.add("-javaagent:" + agentJarFile); // Only on false, ie test the 'true' default with no option if (!logConfig) { command.add("-D" + ConfigLoggingAgentListener.LOG_THE_CONFIG + "=false"); } - command.add(testTargetClass.getAbsolutePath()); + command.add("-cp"); + command.add(testTargetCompiledClass.getParentFile().getAbsolutePath()); + command.add(TARGET_CLASS_NAME); return command; } + static void compileTestTarget(File sourceFile) throws IOException { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + if (compiler.run(null, null, null, sourceFile.getAbsolutePath()) != 0) { + throw new IOException("Failed to compile test target"); + } + } + static File createTestTarget() throws IOException { String targetClass = "public class " From e31620b8f7562becda6d24eaae15a7e89520e775 Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Thu, 27 Nov 2025 21:56:44 +0000 Subject: [PATCH 22/23] remove eager logging init --- .../java/co/elastic/otel/logging/ElasticLoggingCustomizer.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal-logging/src/main/java/co/elastic/otel/logging/ElasticLoggingCustomizer.java b/internal-logging/src/main/java/co/elastic/otel/logging/ElasticLoggingCustomizer.java index 59787b68..55203fac 100644 --- a/internal-logging/src/main/java/co/elastic/otel/logging/ElasticLoggingCustomizer.java +++ b/internal-logging/src/main/java/co/elastic/otel/logging/ElasticLoggingCustomizer.java @@ -41,9 +41,6 @@ public void init(EarlyInitAgentConfig earlyConfig) { // trigger loading the slf4j provider from the agent CL, this should load log4j implementation LoggerFactory.getILoggerFactory(); - // make the agent internal logger delegate to slf4j, which will delegate to log4j - InternalLogger.initialize(Slf4jInternalLogger::create); - boolean upstreamDebugEnabled = earlyConfig.getBoolean(AgentLog.OTEL_JAVAAGENT_DEBUG, false); Level level; if (upstreamDebugEnabled) { From 64b86f07dca7d64dbcf48c8a39ef789ee9c3e2cf Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Thu, 27 Nov 2025 23:10:37 +0000 Subject: [PATCH 23/23] spotless --- .../java/co/elastic/otel/logging/ElasticLoggingCustomizer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/internal-logging/src/main/java/co/elastic/otel/logging/ElasticLoggingCustomizer.java b/internal-logging/src/main/java/co/elastic/otel/logging/ElasticLoggingCustomizer.java index 55203fac..8a6c05e3 100644 --- a/internal-logging/src/main/java/co/elastic/otel/logging/ElasticLoggingCustomizer.java +++ b/internal-logging/src/main/java/co/elastic/otel/logging/ElasticLoggingCustomizer.java @@ -19,7 +19,6 @@ package co.elastic.otel.logging; import com.google.auto.service.AutoService; -import io.opentelemetry.javaagent.bootstrap.InternalLogger; import io.opentelemetry.javaagent.tooling.LoggingCustomizer; import io.opentelemetry.javaagent.tooling.config.EarlyInitAgentConfig; import java.util.Optional;