Skip to content

Commit c71d34c

Browse files
committed
feat(profiler): emit synthetic SpanNode events for ThreadPoolExecutor worker threads
1 parent a484345 commit c71d34c

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

  • dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/Wrapper.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import static datadog.trace.bootstrap.instrumentation.java.concurrent.ExcludeFilter.exclude;
77

88
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
9+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
10+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
11+
import datadog.trace.bootstrap.instrumentation.api.ProfilerContext;
912
import java.util.concurrent.RunnableFuture;
1013

1114
public class Wrapper<T extends Runnable> implements Runnable, AutoCloseable {
@@ -44,7 +47,23 @@ public Wrapper(T delegate, AgentScope.Continuation continuation) {
4447
@Override
4548
public void run() {
4649
try (AgentScope scope = activate()) {
47-
delegate.run();
50+
long startNano = 0L;
51+
ProfilerContext profilerCtx = null;
52+
if (scope != null) {
53+
AgentSpan span = scope.span();
54+
if (span != null && span.context() instanceof ProfilerContext) {
55+
profilerCtx = (ProfilerContext) span.context();
56+
startNano = System.nanoTime();
57+
AgentTracer.get().getProfilingContext().onTaskActivation(profilerCtx, startNano);
58+
}
59+
}
60+
try {
61+
delegate.run();
62+
} finally {
63+
if (profilerCtx != null) {
64+
AgentTracer.get().getProfilingContext().onTaskDeactivation(profilerCtx, startNano);
65+
}
66+
}
4867
}
4968
}
5069

0 commit comments

Comments
 (0)