From dbb5d5194860105f6238b95c6e12181e76c00d9c Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Tue, 21 Apr 2026 19:57:40 +0200 Subject: [PATCH 1/5] declarative config metrics delta --- custom/src/main/resources/co/elastic/otel/config.yaml | 2 ++ .../otel/declarativeconfig/DefaultDeclarativeConfigTest.java | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/custom/src/main/resources/co/elastic/otel/config.yaml b/custom/src/main/resources/co/elastic/otel/config.yaml index 0fde6564..e9d55229 100644 --- a/custom/src/main/resources/co/elastic/otel/config.yaml +++ b/custom/src/main/resources/co/elastic/otel/config.yaml @@ -47,10 +47,12 @@ meter_provider: otlp_http: endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/metrics headers_list: ${OTEL_EXPORTER_OTLP_HEADERS} + temporality_preference: delta # use the following for grpc # otlp_grpc: # endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT} # headers_list: ${OTEL_EXPORTER_OTLP_HEADERS} + # temporality_preference: delta logger_provider: processors: diff --git a/custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java b/custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java index 8387b3c0..ad9e93da 100644 --- a/custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java +++ b/custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java @@ -78,7 +78,8 @@ void testDefaults() { assertThatJson(json(config.getMeterProvider().getReaders().get(0))) .inPath("periodic.exporter.otlp_http") .isObject() - .containsEntry("endpoint", "http://localhost:4318/v1/metrics"); + .containsEntry("endpoint", "http://localhost:4318/v1/metrics") + .containsEntry("temporality_preference", "delta"); assertThat(config.getLoggerProvider()).isNotNull(); assertThat(config.getLoggerProvider().getProcessors()).hasSize(1); From 212ca78afc3949024521f6f20170a390354925f4 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Tue, 21 Apr 2026 20:53:22 +0200 Subject: [PATCH 2/5] refactor test a bit + fix things --- .../smoketest/AppServerProvidersTest.java | 20 ++-- .../javaagent/smoketest/SmokeTest.java | 100 +++++++++++------- .../javaagent/smoketest/TestAppSmokeTest.java | 20 ++-- 3 files changed, 82 insertions(+), 58 deletions(-) diff --git a/smoke-tests/src/test/java/com/example/javaagent/smoketest/AppServerProvidersTest.java b/smoke-tests/src/test/java/com/example/javaagent/smoketest/AppServerProvidersTest.java index 3ffe37ab..e6c869c1 100644 --- a/smoke-tests/src/test/java/com/example/javaagent/smoketest/AppServerProvidersTest.java +++ b/smoke-tests/src/test/java/com/example/javaagent/smoketest/AppServerProvidersTest.java @@ -60,15 +60,17 @@ static void afterAll() { @Test void tomcat() { target = - startTarget( - "tomcat:latest", - container -> - container - .withExposedPorts(PORT) - .waitingFor(Wait.forListeningPorts(PORT)) - .withCopyFileToContainer( - MountableFile.forHostPath(testAppWar), - "/usr/local/tomcat/webapps/app.war")); + testTarget("tomcat:latest") + .withBaseEnvironmentVariables(true) + .customize( + container -> + container + .withExposedPorts(PORT) + .waitingFor(Wait.forListeningPorts(PORT)) + .withCopyFileToContainer( + MountableFile.forHostPath(testAppWar), + "/usr/local/tomcat/webapps/app.war")) + .start(); await() .atMost(Duration.ofSeconds(30)) diff --git a/smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java b/smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java index 5ab6f241..49a9cfc1 100644 --- a/smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java +++ b/smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java @@ -108,55 +108,79 @@ static void setupSpec() { backend.start(); } - protected static GenericContainer startTarget( - String image, Consumer> customizeContainer) { + public static TestTarget testTarget(String image) { + return new TestTarget(image); + } - @SuppressWarnings("resource") - GenericContainer target = - new GenericContainer<>(image) - .withNetwork(network) - .withLogConsumer(new Slf4jLogConsumer(logger)) - .withCopyFileToContainer(MountableFile.forHostPath(AGENT_PATH), JAVAAGENT_JAR_PATH); + public static class TestTarget { + private final String image; + private Consumer> customizeContainer; + private boolean baseEnvVariables; - StringBuilder jvmArgs = new StringBuilder(); + public TestTarget(String image) { + this.image = image; + } - if (JavaExecutable.isDebugging()) { - // when debugging, automatically use verbose debug logging - target.withEnv("OTEL_JAVAAGENT_DEBUG", "true"); + public TestTarget customize(Consumer> customizeContainer) { + this.customizeContainer = customizeContainer; + return this; + } - if (JavaExecutable.isListeningDebuggerStarted(TARGET_DEBUG_PORT, "target")) { - target = addDockerDebugHost(target); - jvmArgs - .append(JavaExecutable.jvmDebugArgument("remote-localhost", TARGET_DEBUG_PORT)) - .append(" "); - } - // Use very long startup delay when debugging as the remote JVM is likely stopped before the - // app has started - target.waitingFor(Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(10))); + public TestTarget withBaseEnvironmentVariables(boolean value) { + this.baseEnvVariables = value; + return this; } - jvmArgs.append(JavaExecutable.jvmAgentArgument(JAVAAGENT_JAR_PATH)); - target.withEnv("JAVA_TOOL_OPTIONS", jvmArgs.toString()); + public GenericContainer start() { + @SuppressWarnings("resource") + GenericContainer target = + new GenericContainer<>(image) + .withNetwork(network) + .withLogConsumer(new Slf4jLogConsumer(logger)) + .withCopyFileToContainer(MountableFile.forHostPath(AGENT_PATH), JAVAAGENT_JAR_PATH); + + StringBuilder jvmArgs = new StringBuilder(); + + if (JavaExecutable.isDebugging()) { + // when debugging, automatically use verbose debug logging + target.withEnv("OTEL_JAVAAGENT_DEBUG", "true"); + + if (JavaExecutable.isListeningDebuggerStarted(TARGET_DEBUG_PORT, "target")) { + target = addDockerDebugHost(target); + jvmArgs + .append(JavaExecutable.jvmDebugArgument("remote-localhost", TARGET_DEBUG_PORT)) + .append(" "); + } + // Use very long startup delay when debugging as the remote JVM is likely stopped before the + // app has started + target.waitingFor(Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(10))); + } - customizeContainer.accept(target); + jvmArgs.append(JavaExecutable.jvmAgentArgument(JAVAAGENT_JAR_PATH)); + target.withEnv("JAVA_TOOL_OPTIONS", jvmArgs.toString()); + + if (baseEnvVariables) { + target + // batch span processor: very small batch size for testing + .withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1") + // batch span processor: very short delay for testing + .withEnv("OTEL_BSP_SCHEDULE_DELAY", "10") + // use grpc endpoint as default is now http/protobuf with agent 2.x + .withEnv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc") + .withEnv("OTEL_PROPAGATORS", "tracecontext,baggage") + .withEnv("OTEL_EXPORTER_OTLP_ENDPOINT", BACKEND_ENDPOINT); + } - Objects.requireNonNull(target).start(); + if (customizeContainer != null) { + customizeContainer.accept(target); + } - startedContainers.add(target); + Objects.requireNonNull(target).start(); - return target; - } + startedContainers.add(target); - protected static void setBaseEnvironmentVariables(GenericContainer target) { - target - // batch span processor: very small batch size for testing - .withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1") - // batch span processor: very short delay for testing - .withEnv("OTEL_BSP_SCHEDULE_DELAY", "10") - // use grpc endpoint as default is now http/protobuf with agent 2.x - .withEnv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc") - .withEnv("OTEL_PROPAGATORS", "tracecontext,baggage") - .withEnv("OTEL_EXPORTER_OTLP_ENDPOINT", BACKEND_ENDPOINT); + return target; + } } private static GenericContainer addDockerDebugHost(GenericContainer target) { diff --git a/smoke-tests/src/test/java/com/example/javaagent/smoketest/TestAppSmokeTest.java b/smoke-tests/src/test/java/com/example/javaagent/smoketest/TestAppSmokeTest.java index 041d5aad..04d4c197 100644 --- a/smoke-tests/src/test/java/com/example/javaagent/smoketest/TestAppSmokeTest.java +++ b/smoke-tests/src/test/java/com/example/javaagent/smoketest/TestAppSmokeTest.java @@ -37,17 +37,15 @@ public static void startTestApp(Consumer> customizeContainer public static void startTestApp( Consumer> customizeContainer, boolean defaultEnv) { target = - startTarget( - TEST_APP_IMAGE, - customizeContainer.andThen( - container -> { - if (defaultEnv) { - setBaseEnvironmentVariables(container); - } - container - .withExposedPorts(PORT) - .waitingFor(Wait.forHttp("/health").forPort(PORT)); - })); + testTarget(TEST_APP_IMAGE) + .withBaseEnvironmentVariables(defaultEnv) + .customize( + customizeContainer.andThen( + container -> + container + .withExposedPorts(PORT) + .waitingFor(Wait.forHttp("/health").forPort(PORT)))) + .start(); } protected static String getContainerId() { From 4a836b26055c37159720383c5ec6c7f72ef61d4c Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 22 Apr 2026 10:20:37 +0200 Subject: [PATCH 3/5] provide env variable to override temporality --- custom/src/main/resources/co/elastic/otel/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/src/main/resources/co/elastic/otel/config.yaml b/custom/src/main/resources/co/elastic/otel/config.yaml index e9d55229..0384c114 100644 --- a/custom/src/main/resources/co/elastic/otel/config.yaml +++ b/custom/src/main/resources/co/elastic/otel/config.yaml @@ -72,4 +72,4 @@ instrumentation/development: java: runtime_telemetry: # emit not-yet stable runtime telemetry metrics which are currently part of semconv for java runtime - emit_experimental_metrics/development: true + emit_experimental_metrics/development: ${OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE:-true} From bf00aaf6010178767186a52b8fd6d14836041281 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 22 Apr 2026 10:36:22 +0200 Subject: [PATCH 4/5] fix pebkc --- custom/src/main/resources/co/elastic/otel/config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom/src/main/resources/co/elastic/otel/config.yaml b/custom/src/main/resources/co/elastic/otel/config.yaml index 0384c114..ca54980a 100644 --- a/custom/src/main/resources/co/elastic/otel/config.yaml +++ b/custom/src/main/resources/co/elastic/otel/config.yaml @@ -47,7 +47,7 @@ meter_provider: otlp_http: endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/metrics headers_list: ${OTEL_EXPORTER_OTLP_HEADERS} - temporality_preference: delta + temporality_preference: ${OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE:-delta} # use the following for grpc # otlp_grpc: # endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT} @@ -72,4 +72,4 @@ instrumentation/development: java: runtime_telemetry: # emit not-yet stable runtime telemetry metrics which are currently part of semconv for java runtime - emit_experimental_metrics/development: ${OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE:-true} + emit_experimental_metrics/development: ${OTEL_INSTRUMENTATION_RUNTIME_TELEMETRY_EMIT_EXPERIMENTAL_METRICS:-true} From 89a79c81c02bfd79024d1a6ea00ff2ae81d60406 Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 22 Apr 2026 10:38:07 +0200 Subject: [PATCH 5/5] update comment for grpc --- custom/src/main/resources/co/elastic/otel/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/src/main/resources/co/elastic/otel/config.yaml b/custom/src/main/resources/co/elastic/otel/config.yaml index ca54980a..c22c1a9e 100644 --- a/custom/src/main/resources/co/elastic/otel/config.yaml +++ b/custom/src/main/resources/co/elastic/otel/config.yaml @@ -52,7 +52,7 @@ meter_provider: # otlp_grpc: # endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT} # headers_list: ${OTEL_EXPORTER_OTLP_HEADERS} - # temporality_preference: delta + # temporality_preference: ${OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE:-delta} logger_provider: processors: