Skip to content

Commit 47cc821

Browse files
Fixed Netty scheduled executor context propagation on newer versions of netty starting at 4.1.44 (2019-12-18).
1 parent 10e03bd commit 47cc821

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

dd-java-agent/instrumentation/java/java-concurrent/java-concurrent-1.8/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ addTestSuiteForDir('latestDepTest', 'test')
1515
dependencies {
1616
testImplementation project(':dd-java-agent:instrumentation:datadog:tracing:trace-annotation')
1717
testImplementation libs.guava
18-
testImplementation group: 'io.netty', name: 'netty-all', version: '4.1.9.Final'
18+
testImplementation group: 'io.netty', name: 'netty-all', version: '4.1.50.Final'
1919
testImplementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '7.0.0'
2020
// Tomcat 10.1.+ seems to require Java 11. Limit to fix build.
2121
// TODO: Tomcat 10.0.10 has a copy of the JSR166 ThreadPoolExecutor so it needs special instrumentation

dd-java-agent/instrumentation/java/java-concurrent/java-concurrent-1.8/src/main/java/datadog/trace/instrumentation/java/concurrent/runnable/RunnableFutureInstrumentation.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.Map;
3232
import java.util.concurrent.Callable;
3333
import java.util.concurrent.RunnableFuture;
34+
import java.util.concurrent.ScheduledFuture;
35+
import java.util.concurrent.TimeUnit;
3436
import net.bytebuddy.asm.Advice;
3537
import net.bytebuddy.description.type.TypeDescription;
3638
import net.bytebuddy.matcher.ElementMatcher;
@@ -147,6 +149,13 @@ public static <T> void captureScope(@Advice.This RunnableFuture<T> task) {
147149
public static final class Run {
148150
@Advice.OnMethodEnter
149151
public static <T> AgentScope activate(@Advice.This RunnableFuture<T> task) {
152+
// Newer Netty versions may run scheduled tasks once before they expire to enqueue them.
153+
if (task instanceof ScheduledFuture
154+
&& task.getClass().getName().endsWith(".netty.util.concurrent.ScheduledFutureTask")
155+
&& ((ScheduledFuture<?>) task).getDelay(TimeUnit.NANOSECONDS) > 0) {
156+
return null;
157+
}
158+
150159
return startTaskScope(InstrumentationContext.get(RunnableFuture.class, State.class), task);
151160
}
152161

0 commit comments

Comments
 (0)