Skip to content

Commit cf070a5

Browse files
committed
fix(core): Fix last parent id injection into trace state
1 parent 3b66caa commit cf070a5

File tree

4 files changed

+11
-41
lines changed

4 files changed

+11
-41
lines changed

dd-trace-core/src/main/java/datadog/trace/core/DDSpanContext.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.core;
22

3+
import static datadog.trace.api.DDTags.PARENT_ID;
34
import static datadog.trace.api.DDTags.SPAN_LINKS;
45
import static datadog.trace.api.cache.RadixTreeCache.HTTP_STATUSES;
56
import static datadog.trace.bootstrap.instrumentation.api.ErrorPriorities.UNSET;
@@ -143,7 +144,6 @@ public class DDSpanContext
143144
private volatile int encodedOperationName;
144145
private volatile int encodedResourceName;
145146
private volatile CharSequence lastParentId;
146-
private final boolean isRemote;
147147

148148
/**
149149
* Metastruct keys are associated to the current span, they will not propagate to the children
@@ -194,8 +194,7 @@ public DDSpanContext(
194194
disableSamplingMechanismValidation,
195195
propagationTags,
196196
ProfilingContextIntegration.NoOp.INSTANCE,
197-
true,
198-
false);
197+
true);
199198
}
200199

201200
public DDSpanContext(
@@ -241,8 +240,7 @@ public DDSpanContext(
241240
disableSamplingMechanismValidation,
242241
propagationTags,
243242
ProfilingContextIntegration.NoOp.INSTANCE,
244-
injectBaggageAsTags,
245-
false);
243+
injectBaggageAsTags);
246244
}
247245

248246
public DDSpanContext(
@@ -288,8 +286,7 @@ public DDSpanContext(
288286
disableSamplingMechanismValidation,
289287
propagationTags,
290288
profilingContextIntegration,
291-
true,
292-
false);
289+
true);
293290
}
294291

295292
public DDSpanContext(
@@ -314,8 +311,7 @@ public DDSpanContext(
314311
final boolean disableSamplingMechanismValidation,
315312
final PropagationTags propagationTags,
316313
final ProfilingContextIntegration profilingContextIntegration,
317-
final boolean injectBaggageAsTags,
318-
final boolean isRemote) {
314+
final boolean injectBaggageAsTags) {
319315

320316
assert traceCollector != null;
321317
this.traceCollector = traceCollector;
@@ -374,8 +370,7 @@ public DDSpanContext(
374370
if (samplingPriority != PrioritySampling.UNSET) {
375371
setSamplingPriority(samplingPriority, SamplingMechanism.UNKNOWN);
376372
}
377-
setLastParentId(this.propagationTags.getLastParentId());
378-
this.isRemote = isRemote;
373+
setTag(PARENT_ID, this.propagationTags.getLastParentId());
379374
}
380375

381376
@Override
@@ -1043,20 +1038,8 @@ public void setMetaStructCurrent(String field, Object value) {
10431038
setMetaStruct(field, value);
10441039
}
10451040

1046-
public CharSequence getLastParentId() {
1047-
return lastParentId;
1048-
}
1049-
1050-
public void setLastParentId(CharSequence lastParentId) {
1051-
if (lastParentId != null) {
1052-
synchronized (unsafeTags) {
1053-
unsafeSetTag("_dd.parent_id", lastParentId);
1054-
}
1055-
this.lastParentId = lastParentId;
1056-
}
1057-
}
1058-
1041+
@Override
10591042
public boolean isRemote() {
1060-
return isRemote;
1043+
return false;
10611044
}
10621045
}

dd-trace-core/src/main/java/datadog/trace/core/propagation/W3CHttpCodec.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,7 @@ private <C> void injectTraceParent(DDSpanContext context, C carrier, CarrierSett
8181

8282
private <C> void injectTraceState(DDSpanContext context, C carrier, CarrierSetter<C> setter) {
8383
PropagationTags propagationTags = context.getPropagationTags();
84-
if (propagationTags.getLastParentId() == null) {
85-
if (context.isRemote()) {
86-
CharSequence lastParentId = context.getLastParentId();
87-
if (lastParentId != null) {
88-
propagationTags.updateLastParentId(lastParentId);
89-
}
90-
} else {
91-
propagationTags.updateLastParentId(DDSpanId.toHexStringPadded(context.getSpanId()));
92-
}
93-
}
94-
84+
propagationTags.updateLastParentId(DDSpanId.toHexStringPadded(context.getSpanId()));
9585
String tracestate = propagationTags.headerValue(W3C);
9686
if (tracestate != null && !tracestate.isEmpty()) {
9787
setter.set(carrier, TRACE_STATE_KEY, tracestate);

dd-trace-core/src/test/groovy/datadog/trace/core/CoreSpanBuilderTest.groovy

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,7 @@ class CoreSpanBuilderTest extends DDCoreSpecification {
374374
span.traceId != extractedContext.traceId
375375
span.parentId != extractedContext.spanId
376376
span.samplingPriority() == PrioritySampling.UNSET
377-
378-
379-
assert span.links.size() == 0
377+
span.links.empty
380378
}
381379

382380
def "TagContext should populate default span details"() {

dd-trace-core/src/test/groovy/datadog/trace/core/test/DDCoreSpecification.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ abstract class DDCoreSpecification extends DDSpecification {
8181
false,
8282
propagationTags,
8383
ProfilingContextIntegration.NoOp.INSTANCE,
84-
true,
85-
false)
84+
true)
8685

8786
def span = DDSpan.create("test", timestamp, context, null)
8887
for (Map.Entry<String, Object> e : tags.entrySet()) {

0 commit comments

Comments
 (0)