Skip to content

Commit 004ea1f

Browse files
committed
fix(core): Fix last parent id injection into trace state
1 parent cf88c2c commit 004ea1f

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;
@@ -145,7 +146,6 @@ public class DDSpanContext
145146
private volatile int encodedOperationName;
146147
private volatile int encodedResourceName;
147148
private volatile CharSequence lastParentId;
148-
private final boolean isRemote;
149149

150150
/**
151151
* Metastruct keys are associated to the current span, they will not propagate to the children
@@ -196,8 +196,7 @@ public DDSpanContext(
196196
disableSamplingMechanismValidation,
197197
propagationTags,
198198
ProfilingContextIntegration.NoOp.INSTANCE,
199-
true,
200-
false);
199+
true);
201200
}
202201

203202
public DDSpanContext(
@@ -243,8 +242,7 @@ public DDSpanContext(
243242
disableSamplingMechanismValidation,
244243
propagationTags,
245244
ProfilingContextIntegration.NoOp.INSTANCE,
246-
injectBaggageAsTags,
247-
false);
245+
injectBaggageAsTags);
248246
}
249247

250248
public DDSpanContext(
@@ -290,8 +288,7 @@ public DDSpanContext(
290288
disableSamplingMechanismValidation,
291289
propagationTags,
292290
profilingContextIntegration,
293-
true,
294-
false);
291+
true);
295292
}
296293

297294
public DDSpanContext(
@@ -316,8 +313,7 @@ public DDSpanContext(
316313
final boolean disableSamplingMechanismValidation,
317314
final PropagationTags propagationTags,
318315
final ProfilingContextIntegration profilingContextIntegration,
319-
final boolean injectBaggageAsTags,
320-
final boolean isRemote) {
316+
final boolean injectBaggageAsTags) {
321317

322318
assert traceCollector != null;
323319
this.traceCollector = traceCollector;
@@ -376,8 +372,7 @@ public DDSpanContext(
376372
if (samplingPriority != PrioritySampling.UNSET) {
377373
setSamplingPriority(samplingPriority, SamplingMechanism.UNKNOWN);
378374
}
379-
setLastParentId(this.propagationTags.getLastParentId());
380-
this.isRemote = isRemote;
375+
setTag(PARENT_ID, this.propagationTags.getLastParentId());
381376
}
382377

383378
@Override
@@ -1055,20 +1050,8 @@ public void setMetaStructCurrent(String field, Object value) {
10551050
setMetaStruct(field, value);
10561051
}
10571052

1058-
public CharSequence getLastParentId() {
1059-
return lastParentId;
1060-
}
1061-
1062-
public void setLastParentId(CharSequence lastParentId) {
1063-
if (lastParentId != null) {
1064-
synchronized (unsafeTags) {
1065-
unsafeSetTag("_dd.parent_id", lastParentId);
1066-
}
1067-
this.lastParentId = lastParentId;
1068-
}
1069-
}
1070-
1053+
@Override
10711054
public boolean isRemote() {
1072-
return isRemote;
1055+
return false;
10731056
}
10741057
}

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)