diff --git a/instrumentation/executors/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeInstrumentation.java b/instrumentation/executors/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeInstrumentation.java index 1b67b6e36e8e..c5c06f8e9009 100644 --- a/instrumentation/executors/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeInstrumentation.java +++ b/instrumentation/executors/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeInstrumentation.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.executors; import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import io.opentelemetry.context.Context; @@ -24,7 +25,10 @@ public class StructuredTaskScopeInstrumentation implements TypeInstrumentation { @Override public ElementMatcher typeMatcher() { - return named("java.util.concurrent.StructuredTaskScope"); + return namedOneOf( + "java.util.concurrent.StructuredTaskScope", + // since jdk 25-ea+24 + "java.util.concurrent.StructuredTaskScopeImpl"); } @Override diff --git a/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeTest.java b/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeTest.java index 595f1c8c40ff..e4ce3bd2a556 100644 --- a/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeTest.java +++ b/instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeTest.java @@ -21,9 +21,24 @@ class StructuredTaskScopeTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); + @SuppressWarnings({ + "unchecked", + "rawtypes" + }) // type arguments for StructuredTaskScope change between jdk 21 and 25 @Test void multipleForkJoin() throws Exception { - StructuredTaskScope taskScope = new StructuredTaskScope.ShutdownOnFailure(); + StructuredTaskScope tmp; + try { + // since jdk 25-ea+24 + tmp = (StructuredTaskScope) StructuredTaskScope.class.getMethod("open").invoke(null); + } catch (NoSuchMethodException exception) { + tmp = + Class.forName("java.util.concurrent.StructuredTaskScope$ShutdownOnFailure") + .asSubclass(StructuredTaskScope.class) + .getConstructor() + .newInstance(); + } + StructuredTaskScope taskScope = tmp; Callable callable1 = () -> {