Cleaner way to skip netty executor's tasks
@@ -26,11 +26,24 @@ public class ExecutorInstrumentationUtils {
* @return true iff given task object should be wrapped
*/
public static boolean shouldAttachStateToTask(final Object task, final Executor executor) {
+ if (task == null) {
+ return false;
+ }
+
final TraceScope scope = activeScope();
- return (scope != null
+ final Class enclosingClass = task.getClass().getEnclosingClass();
+
+ return scope != null
&& scope.isAsyncPropagating()
- && task != null
- && !ExecutorInstrumentationUtils.isExecutorDisabledForThisTask(executor, task));
+ && !ExecutorInstrumentationUtils.isExecutorDisabledForThisTask(executor, task)
+
+ // Don't instrument the executor's own runnables. These runnables may never return until
+ // netty shuts down. Any created continuations will be open until that time preventing
+ // traces from being reported
+ && (enclosingClass == null
+ || !enclosingClass
+ .getName()
+ .equals("io.netty.util.concurrent.SingleThreadEventExecutor"));
}
/**
@@ -47,20 +60,13 @@ public class ExecutorInstrumentationUtils {
final State state = contextStore.putIfAbsent(task, State.FACTORY);
- // Don't instrument the executor's own runnables. These runnables may never return until
- // netty shuts down. Any created continuations will be open until that time preventing traces
- // from being reported
- if (!task.getClass()
- .getName()
- .startsWith("io.netty.util.concurrent.SingleThreadEventExecutor$")) {
-
final TraceScope.Continuation continuation = scope.capture();
if (state.setContinuation(continuation)) {
log.debug("created continuation {} from scope {}, state: {}", continuation, scope, state);
} else {
continuation.close(false);
}
- }
+
return state;
}
