Skip to content

Commit 5c5b320

Browse files
committed
feat(profiler): wire submittingSpanId into QueueTime events
1 parent b5306f1 commit 5c5b320

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof/DatadogProfiler.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ public void recordSetting(String name, String value, String unit) {
453453
profiler.recordSetting(name, value, unit);
454454
}
455455

456-
public QueueTimeTracker newQueueTimeTracker() {
457-
return new QueueTimeTracker(this, profiler.getCurrentTicks());
456+
public QueueTimeTracker newQueueTimeTracker(long submittingSpanId) {
457+
return new QueueTimeTracker(this, profiler.getCurrentTicks(), submittingSpanId);
458458
}
459459

460460
boolean shouldRecordQueueTimeEvent(long startMillis) {
@@ -495,15 +495,23 @@ void recordQueueTimeEvent(
495495
Class<?> scheduler,
496496
Class<?> queueType,
497497
int queueLength,
498-
Thread origin) {
498+
Thread origin,
499+
long submittingSpanId) {
499500
if (profiler != null) {
500501
// note: because this type traversal can update secondary_super_cache (see JDK-8180450)
501502
// we avoid doing this unless we are absolutely certain we will record the event
502503
Class<?> taskType = TaskWrapper.getUnwrappedType(task);
503504
if (taskType != null) {
504505
long endTicks = profiler.getCurrentTicks();
505506
profiler.recordQueueTime(
506-
startTicks, endTicks, taskType, scheduler, queueType, queueLength, origin);
507+
startTicks,
508+
endTicks,
509+
taskType,
510+
scheduler,
511+
queueType,
512+
queueLength,
513+
origin,
514+
submittingSpanId);
507515
}
508516
}
509517
}

dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof/DatadogProfilingIntegration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import datadog.trace.api.profiling.ProfilingScope;
77
import datadog.trace.api.profiling.Timing;
88
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
9+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
910
import datadog.trace.bootstrap.instrumentation.api.ProfilerContext;
1011
import datadog.trace.bootstrap.instrumentation.api.ProfilingContextIntegration;
1112

@@ -164,7 +165,10 @@ public EndpointTracker onRootSpanStarted(AgentSpan rootSpan) {
164165
@Override
165166
public Timing start(TimerType type) {
166167
if (IS_PROFILING_QUEUEING_TIME_ENABLED && type == TimerType.QUEUEING) {
167-
return DDPROF.newQueueTimeTracker();
168+
AgentSpan span = AgentTracer.activeSpan();
169+
long submittingSpanId =
170+
(span instanceof ProfilerContext) ? ((ProfilerContext) span).getSpanId() : 0L;
171+
return DDPROF.newQueueTimeTracker(submittingSpanId);
168172
}
169173
return Timing.NoOp.INSTANCE;
170174
}

dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof/QueueTimeTracker.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ public class QueueTimeTracker implements QueueTiming {
99
private final Thread origin;
1010
private final long startTicks;
1111
private final long startMillis;
12+
private final long submittingSpanId;
1213
private WeakReference<Object> weakTask;
1314
// FIXME this can be eliminated by altering the instrumentation
1415
// since it is known when the item is polled from the queue
1516
private Class<?> scheduler;
1617
private Class<?> queue;
1718
private int queueLength;
1819

19-
public QueueTimeTracker(DatadogProfiler profiler, long startTicks) {
20+
public QueueTimeTracker(DatadogProfiler profiler, long startTicks, long submittingSpanId) {
2021
this.profiler = profiler;
2122
this.origin = Thread.currentThread();
2223
this.startTicks = startTicks;
2324
this.startMillis = System.currentTimeMillis();
25+
this.submittingSpanId = submittingSpanId;
2426
}
2527

2628
@Override
@@ -49,7 +51,8 @@ public void report() {
4951
Object task = this.weakTask.get();
5052
if (task != null) {
5153
// indirection reduces shallow size of the tracker instance
52-
profiler.recordQueueTimeEvent(startTicks, task, scheduler, queue, queueLength, origin);
54+
profiler.recordQueueTimeEvent(
55+
startTicks, task, scheduler, queue, queueLength, origin, submittingSpanId);
5356
}
5457
}
5558

0 commit comments

Comments
 (0)