diff --git a/.github/workflows/auto-update-otel-sdk.yml b/.github/workflows/auto-update-otel-sdk.yml index b99786badf8c..fb40c6ca809a 100644 --- a/.github/workflows/auto-update-otel-sdk.yml +++ b/.github/workflows/auto-update-otel-sdk.yml @@ -69,7 +69,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 diff --git a/.github/workflows/build-common.yml b/.github/workflows/build-common.yml index 2ea04e799b11..fddcd2b85900 100644 --- a/.github/workflows/build-common.yml +++ b/.github/workflows/build-common.yml @@ -35,7 +35,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 @@ -68,7 +68,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 @@ -138,7 +138,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Increase gradle daemon heap size run: | @@ -220,7 +220,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 # vaadin 14 tests fail with node 18 - name: Set up Node @@ -335,7 +335,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Set up Gradle cache uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 @@ -388,7 +388,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 @@ -411,7 +411,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Set up Gradle cache uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a086adb02a8d..60db73b1aa7c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,7 +70,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 diff --git a/.github/workflows/codeql-daily.yml b/.github/workflows/codeql-daily.yml index 68bb9380cb77..5d1b1c56be78 100644 --- a/.github/workflows/codeql-daily.yml +++ b/.github/workflows/codeql-daily.yml @@ -27,7 +27,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Initialize CodeQL uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3 diff --git a/.github/workflows/owasp-dependency-check-daily.yml b/.github/workflows/owasp-dependency-check-daily.yml index b44dca7e1425..b0f208b277a3 100644 --- a/.github/workflows/owasp-dependency-check-daily.yml +++ b/.github/workflows/owasp-dependency-check-daily.yml @@ -22,7 +22,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Increase gradle daemon heap size run: | diff --git a/.github/workflows/pr-smoke-test-fake-backend-images.yml b/.github/workflows/pr-smoke-test-fake-backend-images.yml index 7a11c6b744a8..3f5427f127ab 100644 --- a/.github/workflows/pr-smoke-test-fake-backend-images.yml +++ b/.github/workflows/pr-smoke-test-fake-backend-images.yml @@ -22,7 +22,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 @@ -49,7 +49,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 diff --git a/.github/workflows/pr-smoke-test-servlet-images.yml b/.github/workflows/pr-smoke-test-servlet-images.yml index 8aa311b75e06..d74e1a31551f 100644 --- a/.github/workflows/pr-smoke-test-servlet-images.yml +++ b/.github/workflows/pr-smoke-test-servlet-images.yml @@ -40,7 +40,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Set up Gradle cache uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 diff --git a/.github/workflows/publish-smoke-test-fake-backend-images.yml b/.github/workflows/publish-smoke-test-fake-backend-images.yml index e12dfcb7ce35..5ff323e1c5c8 100644 --- a/.github/workflows/publish-smoke-test-fake-backend-images.yml +++ b/.github/workflows/publish-smoke-test-fake-backend-images.yml @@ -22,7 +22,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Login to GitHub package registry uses: docker/login-action@v3 @@ -55,7 +55,7 @@ jobs: uses: actions/setup-java@v4 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Login to GitHub package registry uses: azure/docker-login@v1 diff --git a/.github/workflows/publish-smoke-test-servlet-images.yml b/.github/workflows/publish-smoke-test-servlet-images.yml index 1e499dea7fb7..43c9600171d3 100644 --- a/.github/workflows/publish-smoke-test-servlet-images.yml +++ b/.github/workflows/publish-smoke-test-servlet-images.yml @@ -57,7 +57,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Login to GitHub package registry uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 39cf630482d7..ced4f127dd2d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,7 +83,7 @@ jobs: - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 diff --git a/.github/workflows/reusable-muzzle.yml b/.github/workflows/reusable-muzzle.yml index 4ad97194074d..1e1ce620276e 100644 --- a/.github/workflows/reusable-muzzle.yml +++ b/.github/workflows/reusable-muzzle.yml @@ -31,7 +31,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Setup Gradle uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2 diff --git a/.github/workflows/reusable-smoke-test-images.yml b/.github/workflows/reusable-smoke-test-images.yml index 2ec6f120df91..81ee14c140cb 100644 --- a/.github/workflows/reusable-smoke-test-images.yml +++ b/.github/workflows/reusable-smoke-test-images.yml @@ -47,7 +47,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Login to GitHub package registry if: inputs.publish diff --git a/.github/workflows/reusable-test-indy.yml b/.github/workflows/reusable-test-indy.yml index 21701b0dccca..0618b0899660 100644 --- a/.github/workflows/reusable-test-indy.yml +++ b/.github/workflows/reusable-test-indy.yml @@ -39,7 +39,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Increase gradle daemon heap size run: | diff --git a/.github/workflows/reusable-test-latest-deps.yml b/.github/workflows/reusable-test-latest-deps.yml index 80ce3bde27f7..d1129dd96623 100644 --- a/.github/workflows/reusable-test-latest-deps.yml +++ b/.github/workflows/reusable-test-latest-deps.yml @@ -38,7 +38,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 with: distribution: temurin - java-version: 17.0.6 + java-version: 21 - name: Increase gradle daemon heap size run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 323b4cd83c36..6e25d48220ad 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ and discuss your ideas or propose the changes you wish to make. ## Building -This project requires Java 17 to build and run tests. Newer JDK's may work, but this version is used in CI. +This project requires Java 21 to build and run tests. Newer JDK's may work, but this version is used in CI. Some instrumentations and tests may put constraints on which java versions they support. See [Running the tests](./docs/contributing/running-tests.md) for more details. @@ -22,7 +22,7 @@ the Sonatype OSS snapshots repository at `https://oss.sonatype.org/content/repos ### Building from source -Build using Java 17: +Build using Java 21: ```bash java -version diff --git a/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt b/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt index 195da08a4709..100184a111b4 100644 --- a/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt +++ b/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt @@ -10,6 +10,7 @@ import org.gradle.api.provider.Property abstract class OtelJavaExtension { abstract val minJavaVersionSupported: Property + abstract val maxJavaVersionSupported: Property abstract val maxJavaVersionForTests: Property diff --git a/conventions/src/main/kotlin/otel.java-conventions.gradle.kts b/conventions/src/main/kotlin/otel.java-conventions.gradle.kts index cb31b0cac5ff..e3204b885e9f 100644 --- a/conventions/src/main/kotlin/otel.java-conventions.gradle.kts +++ b/conventions/src/main/kotlin/otel.java-conventions.gradle.kts @@ -27,12 +27,15 @@ afterEvaluate { } // Version to use to compile code and run tests. -val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_17 +val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_21 java { toolchain { languageVersion.set( - otelJava.minJavaVersionSupported.map { JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), DEFAULT_JAVA_VERSION.majorVersion.toInt())) } + otelJava.minJavaVersionSupported.map { + val defaultJavaVersion = otelJava.maxJavaVersionSupported.getOrElse(DEFAULT_JAVA_VERSION).majorVersion.toInt() + JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), defaultJavaVersion)) + } ) } @@ -69,11 +72,18 @@ tasks.withType().configureEach { "-Xlint:-processing", // We suppress the "options" warning because it prevents compilation on modern JDKs "-Xlint:-options", + // jdk21 generates more serial warnings than previous versions + "-Xlint:-serial", // Fail build on any warning "-Werror" ) ) + val defaultJavaVersion = otelJava.maxJavaVersionSupported.getOrElse(DEFAULT_JAVA_VERSION).majorVersion.toInt() + if (Math.max(otelJava.minJavaVersionSupported.get().majorVersion.toInt(), defaultJavaVersion) >= 21) { + // new warning in jdk21 + compilerArgs.add("-Xlint:-this-escape") + } } encoding = "UTF-8" @@ -81,6 +91,11 @@ tasks.withType().configureEach { if (name.contains("Test")) { // serialVersionUID is basically guaranteed to be useless in tests compilerArgs.add("-Xlint:-serial") + // when code is compiled with jdk 21 and executed with jdk 8, the -parameters flag is needed to avoid + // java.lang.reflect.MalformedParametersException: Invalid parameter name "" + // when junit calls java.lang.reflect.Executable.getParameters() on the constructor of a + // non-static nested test class + compilerArgs.add("-parameters") } } } diff --git a/custom-checks/build.gradle.kts b/custom-checks/build.gradle.kts index 8f1e11298c64..f96a4c855e6a 100644 --- a/custom-checks/build.gradle.kts +++ b/custom-checks/build.gradle.kts @@ -36,6 +36,8 @@ tasks { "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", "--add-exports", + "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-exports", "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/testing/build.gradle.kts b/instrumentation/apache-httpclient/apache-httpclient-4.3/testing/build.gradle.kts index ef1efff84e0f..9328255dc436 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/testing/build.gradle.kts +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/testing/build.gradle.kts @@ -2,6 +2,16 @@ plugins { id("otel.java-conventions") } +tasks { + compileJava { + // when code is compiled with jdk 21 and executed with jdk 8 -parameters flag is needed to avoid + // java.lang.reflect.MalformedParametersException: Invalid parameter name "" + // when junit calls java.lang.reflect.Executable.getParameters() on the constructor of a + // non-static nested test class + options.compilerArgs.add("-parameters") + } +} + dependencies { api(project(":testing-common")) diff --git a/instrumentation/camel-2.20/javaagent-unit-tests/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/SanitizationTest.java b/instrumentation/camel-2.20/javaagent-unit-tests/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/SanitizationTest.java index 37b5b708b474..a59f82f86897 100644 --- a/instrumentation/camel-2.20/javaagent-unit-tests/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/SanitizationTest.java +++ b/instrumentation/camel-2.20/javaagent-unit-tests/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/SanitizationTest.java @@ -31,7 +31,7 @@ void sanitizeCql(String original, String expected) { when(exchange.getIn()).thenReturn(message); String actualSanitized = decorator.getStatement(exchange, null); - assertEquals(actualSanitized, expected); + assertEquals(expected, actualSanitized); } @ParameterizedTest @@ -45,7 +45,7 @@ void sanitizeJdbc(String original, String expected) { when(exchange.getIn()).thenReturn(message); String actualSanitized = decorator.getStatement(exchange, null); - assertEquals(actualSanitized, expected); + assertEquals(expected, actualSanitized); } @ParameterizedTest @@ -60,7 +60,7 @@ void sanitizeSql(String original, String expected) { when(exchange.getIn()).thenReturn(message); String actualSanitized = decorator.getStatement(exchange, null); - assertEquals(actualSanitized, expected); + assertEquals(expected, actualSanitized); } static class SqlArgs implements ArgumentsProvider { diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/build.gradle.kts b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/build.gradle.kts index 4ac2c79ffb65..eb8ff28ad473 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/build.gradle.kts +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/build.gradle.kts @@ -28,6 +28,13 @@ muzzle { } } +if (findProperty("testLatestDeps") as Boolean) { + // when running on jdk 21 Elasticsearch53SpringRepositoryTest occasionally fails with timeout + otelJava { + maxJavaVersionSupported.set(JavaVersion.VERSION_17) + } +} + dependencies { compileOnly("org.elasticsearch.client:transport:5.3.0") { isTransitive = false diff --git a/instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/ExecutorInstrumentationTest.java b/instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/ExecutorInstrumentationTest.java index 77a3d0ad7636..aa05c1b6af0f 100644 --- a/instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/ExecutorInstrumentationTest.java +++ b/instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/ExecutorInstrumentationTest.java @@ -7,8 +7,6 @@ import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -26,8 +24,6 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; abstract class ExecutorInstrumentationTest @@ -51,24 +47,6 @@ static class ThreadPoolExecutorTest extends ExecutorInstrumentationTest { - VirtualThreadExecutorTest() { - super(newVirtualThreadPerTaskExecutor()); - } - - private static ExecutorService newVirtualThreadPerTaskExecutor() { - Method newVirtualThreadPerTaskExecutor; - try { - newVirtualThreadPerTaskExecutor = - Executors.class.getMethod("newVirtualThreadPerTaskExecutor"); - return (ExecutorService) newVirtualThreadPerTaskExecutor.invoke(null); - } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) { - throw new IllegalStateException("Should not happen on Java 21+", e); - } - } - } - static class WorkStealingPoolTest extends ExecutorInstrumentationTest { public WorkStealingPoolTest() { super(Executors.newWorkStealingPool(2)); diff --git a/instrumentation/executors/jdk21-testing/build.gradle.kts b/instrumentation/executors/jdk21-testing/build.gradle.kts new file mode 100644 index 000000000000..1de1f41eb701 --- /dev/null +++ b/instrumentation/executors/jdk21-testing/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + id("otel.javaagent-testing") +} + +dependencies { + testInstrumentation(project(":instrumentation:executors:javaagent")) + + testCompileOnly(project(":instrumentation:executors:bootstrap")) + testImplementation(project(":instrumentation:executors:testing")) +} + +otelJava { + minJavaVersionSupported.set(JavaVersion.VERSION_21) +} + +tasks.withType().configureEach { + // needed for VirtualThreadTest + jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") + jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") +} diff --git a/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadExecutorTest.java b/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadExecutorTest.java new file mode 100644 index 000000000000..e9a6e1a1fcdb --- /dev/null +++ b/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadExecutorTest.java @@ -0,0 +1,28 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.executors; + +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.junit.jupiter.api.extension.RegisterExtension; + +class VirtualThreadExecutorTest + extends AbstractExecutorServiceTest { + + @RegisterExtension + static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + VirtualThreadExecutorTest() { + super(Executors.newVirtualThreadPerTaskExecutor(), testing); + } + + @Override + protected JavaAsyncChild newTask(boolean doTraceableWork, boolean blockThread) { + return new JavaAsyncChild(doTraceableWork, blockThread); + } +} diff --git a/instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadTest.java b/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadTest.java similarity index 76% rename from instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadTest.java rename to instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadTest.java index d89e3493936d..924856c6dfca 100644 --- a/instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadTest.java +++ b/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadTest.java @@ -12,21 +12,13 @@ import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; -@EnabledForJreRange(min = JRE.JAVA_21) class VirtualThreadTest { @Test void testDisableContextPropagation() throws Exception { TestRunnable testRunnable = new TestRunnable(); - // Thread.ofVirtual().start(testRunnable); - Method ofVirtualMethod = Thread.class.getMethod("ofVirtual"); - Object virtualThreadBuilder = ofVirtualMethod.invoke(null); - Method startVirtualThread = - Class.forName("java.lang.Thread$Builder").getMethod("start", Runnable.class); - Thread thread = (Thread) startVirtualThread.invoke(virtualThreadBuilder, testRunnable); + Thread thread = Thread.ofVirtual().start(testRunnable); thread.join(); assertThat(testRunnable.error).isNull(); diff --git a/instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/JavaAsyncChild.java b/instrumentation/executors/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/executors/JavaAsyncChild.java similarity index 98% rename from instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/JavaAsyncChild.java rename to instrumentation/executors/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/executors/JavaAsyncChild.java index 68c45abbf04a..fa136cc83e02 100644 --- a/instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/JavaAsyncChild.java +++ b/instrumentation/executors/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/executors/JavaAsyncChild.java @@ -11,6 +11,7 @@ import java.util.concurrent.ForkJoinTask; import java.util.concurrent.atomic.AtomicBoolean; +@SuppressWarnings("serial") final class JavaAsyncChild extends ForkJoinTask implements TestTask { private static final Tracer tracer = GlobalOpenTelemetry.getTracer("test"); diff --git a/instrumentation/grails-3.0/javaagent/build.gradle.kts b/instrumentation/grails-3.0/javaagent/build.gradle.kts index bb6b8f1facda..5e8fbd2e824f 100644 --- a/instrumentation/grails-3.0/javaagent/build.gradle.kts +++ b/instrumentation/grails-3.0/javaagent/build.gradle.kts @@ -18,6 +18,10 @@ muzzle { } } +otelJava { + maxJavaVersionSupported.set(JavaVersion.VERSION_17) +} + val grailsVersion = "3.0.6" // first version that the tests pass on val springBootVersion = "1.2.5.RELEASE" diff --git a/instrumentation/zio/zio-2.0/javaagent/build.gradle.kts b/instrumentation/zio/zio-2.0/javaagent/build.gradle.kts index 38e791471534..9821f649879b 100644 --- a/instrumentation/zio/zio-2.0/javaagent/build.gradle.kts +++ b/instrumentation/zio/zio-2.0/javaagent/build.gradle.kts @@ -28,6 +28,10 @@ muzzle { } } +otelJava { + maxJavaVersionSupported.set(JavaVersion.VERSION_17) +} + dependencies { compileOnly("dev.zio:zio_$scalaVersion:$zioVersion") diff --git a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceMatcher.java b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceMatcher.java index 9bd7b2435502..0726c92c4a05 100644 --- a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceMatcher.java +++ b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceMatcher.java @@ -294,13 +294,19 @@ private static MethodDescription.InDefinedShape findMethod( return null; } + TypeDescription superType = null; if (typeOnClasspath.getSuperClass() != null) { - MethodDescription.InDefinedShape methodOnSupertype = - findMethod(methodRef, typeOnClasspath.getSuperClass().asErasure()); + superType = typeOnClasspath.getSuperClass().asErasure(); + } else if (!"java.lang.Object".equals(typeOnClasspath.getName())) { + superType = TypeDescription.ForLoadedType.of(Object.class); + } + if (superType != null) { + MethodDescription.InDefinedShape methodOnSupertype = findMethod(methodRef, superType); if (methodOnSupertype != null) { return methodOnSupertype; } } + for (TypeDescription.Generic interfaceType : typeOnClasspath.getInterfaces()) { MethodDescription.InDefinedShape methodOnSupertype = findMethod(methodRef, interfaceType.asErasure()); diff --git a/settings.gradle.kts b/settings.gradle.kts index fa8db6167251..dd0559c6a284 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -227,6 +227,7 @@ include(":instrumentation:elasticsearch:elasticsearch-transport-common:javaagent include(":instrumentation:elasticsearch:elasticsearch-transport-common:testing") include(":instrumentation:executors:bootstrap") include(":instrumentation:executors:javaagent") +include(":instrumentation:executors:jdk21-testing") include(":instrumentation:executors:testing") include(":instrumentation:external-annotations:javaagent") include(":instrumentation:external-annotations:javaagent-unit-tests")