diff --git a/javaagent-api/src/main/java/io/opentelemetry/javaagent/instrumentation/api/concurrent/ExecutorInstrumentationUtils.java b/javaagent-api/src/main/java/io/opentelemetry/javaagent/instrumentation/api/concurrent/ExecutorInstrumentationUtils.java index 44900f6a4ef5..6ff1df139924 100644 --- a/javaagent-api/src/main/java/io/opentelemetry/javaagent/instrumentation/api/concurrent/ExecutorInstrumentationUtils.java +++ b/javaagent-api/src/main/java/io/opentelemetry/javaagent/instrumentation/api/concurrent/ExecutorInstrumentationUtils.java @@ -34,7 +34,11 @@ public static boolean shouldAttachStateToTask(Object task) { // TODO Workaround for // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/787 && !taskClass.getName().equals("org.apache.tomcat.util.net.NioEndpoint$SocketProcessor") - // Don't instrument the executor's own runnables. These runnables may never return until + // Avoid context leak on jetty. Runnable submitted from SelectChannelEndPoint is used to + // process a new request which should not have context from them current request. + && (enclosingClass == null + || !enclosingClass.getName().equals("org.eclipse.jetty.io.nio.SelectChannelEndPoint")) + // Don't instrument the executor's own runnables. These runnables may never return until // netty shuts down. && (enclosingClass == null || !enclosingClass