File tree Expand file tree Collapse file tree
dd-trace-core/src/main/java/datadog/trace/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,6 +160,11 @@ private void finishAndAddToTrace(final long durationNano) {
160160 wrapper .onSpanFinished ();
161161 }
162162 this .metrics .onSpanFinished ();
163+ // Capture the execution thread while still on the span's own finishing thread.
164+ // CoreTracer.write() is called later from the event loop; the info captured here is the
165+ // authoritative source for SpanNode thread attribution (see SpanExecutionThreadEvent).
166+ context .captureExecutionThread (
167+ Thread .currentThread ().getId (), Thread .currentThread ().getName ());
163168 TraceCollector .PublishState publishState = context .getTraceCollector ().onPublish (this );
164169 log .debug ("Finished span ({}): {}" , publishState , this );
165170 } else {
Original file line number Diff line number Diff line change @@ -160,6 +160,8 @@ public class DDSpanContext
160160 private final boolean injectBaggageAsTags ;
161161 private volatile int encodedOperationName ;
162162 private volatile int encodedResourceName ;
163+ private volatile long executionThreadId = 0 ;
164+ private volatile String executionThreadName = "" ;
163165
164166 /**
165167 * Metastruct keys are associated to the current span, they will not propagate to the children
@@ -387,6 +389,25 @@ public int getEncodedResourceName() {
387389 return encodedResourceName ;
388390 }
389391
392+ public ProfilingContextIntegration getProfilingContextIntegration () {
393+ return profilingContextIntegration ;
394+ }
395+
396+ void captureExecutionThread (long threadId , String threadName ) {
397+ this .executionThreadId = threadId ;
398+ this .executionThreadName = threadName ;
399+ }
400+
401+ @ Override
402+ public long getExecutionThreadId () {
403+ return executionThreadId ;
404+ }
405+
406+ @ Override
407+ public String getExecutionThreadName () {
408+ return executionThreadName ;
409+ }
410+
390411 public String getServiceName () {
391412 return serviceName ;
392413 }
You can’t perform that action at this time.
0 commit comments