Skip to content

Commit 848f35a

Browse files
authored
Ensure Propagators are still run when DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT=ignore (#8604)
* saving changes * cleanup and adding tests * addressing PR comments * optimizing calls to config
1 parent d08dc3a commit 848f35a

File tree

4 files changed

+40
-41
lines changed

4 files changed

+40
-41
lines changed

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,28 +1514,31 @@ private DDSpanContext buildSpanContext() {
15141514
String parentServiceName = null;
15151515
boolean isRemote = false;
15161516

1517-
if (parentContext != null
1518-
&& parentContext.isRemote()
1519-
&& Config.get().getTracePropagationBehaviorExtract()
1520-
== TracePropagationBehaviorExtract.RESTART) {
1521-
SpanLink link;
1522-
if (parentContext instanceof ExtractedContext) {
1523-
ExtractedContext pc = (ExtractedContext) parentContext;
1524-
link =
1525-
DDSpanLink.from(
1526-
pc,
1527-
SpanAttributes.builder()
1528-
.put("reason", "propagation_behavior_extract")
1529-
.put("context_headers", pc.getPropagationStyle().toString())
1530-
.build());
1531-
} else {
1532-
link = SpanLink.from(parentContext);
1517+
TracePropagationBehaviorExtract behaviorExtract =
1518+
Config.get().getTracePropagationBehaviorExtract();
1519+
if (parentContext != null && parentContext.isRemote()) {
1520+
if (behaviorExtract == TracePropagationBehaviorExtract.IGNORE) {
1521+
// reset links that may have come terminated span links
1522+
links = new ArrayList<>();
1523+
parentContext = null;
1524+
} else if (behaviorExtract == TracePropagationBehaviorExtract.RESTART) {
1525+
links = new ArrayList<>();
1526+
SpanLink link =
1527+
(parentContext instanceof ExtractedContext)
1528+
? DDSpanLink.from(
1529+
(ExtractedContext) parentContext,
1530+
SpanAttributes.builder()
1531+
.put("reason", "propagation_behavior_extract")
1532+
.put(
1533+
"context_headers",
1534+
((ExtractedContext) parentContext).getPropagationStyle().toString())
1535+
.build())
1536+
: SpanLink.from(parentContext);
1537+
links.add(link);
1538+
parentContext = null;
15331539
}
1534-
// reset links that may have come terminated span links
1535-
links = new ArrayList<>();
1536-
links.add(link);
1537-
parentContext = null;
15381540
}
1541+
15391542
// Propagate internal trace.
15401543
// Note: if we are not in the context of distributed tracing and we are starting the first
15411544
// root span, parentContext will be null at this point.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,22 @@ class CoreSpanBuilderTest extends DDCoreSpecification {
363363
link.traceState() == extractedContext.propagationTags.headerValue(PropagationTags.HeaderType.W3C)
364364
}
365365

366+
def "build context from ExtractedContext with TRACE_PROPAGATION_BEHAVIOR_EXTRACT=ignore"() {
367+
setup:
368+
injectSysConfig("trace.propagation.behavior.extract", "ignore")
369+
def extractedContext = new ExtractedContext(DDTraceId.ONE, 2, PrioritySampling.SAMPLER_DROP, null, 0, [:], [:], null, PropagationTags.factory().fromHeaderValue(PropagationTags.HeaderType.DATADOG, "_dd.p.dm=934086a686-4,_dd.p.anytag=value"), null, DATADOG)
370+
final DDSpan span = tracer.buildSpan("test", "op name")
371+
.asChildOf(extractedContext).start()
372+
373+
expect:
374+
span.traceId != extractedContext.traceId
375+
span.parentId != extractedContext.spanId
376+
span.samplingPriority() == PrioritySampling.UNSET
377+
378+
379+
assert span.links.size() == 0
380+
}
381+
366382
def "TagContext should populate default span details"() {
367383
setup:
368384
def thread = Thread.currentThread()

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,8 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins
10421042
}
10431043
// Now we can check if we should pick the default injection/extraction
10441044

1045-
if (extract.isEmpty()) {
1046-
extract = DEFAULT_TRACE_PROPAGATION_STYLE;
1047-
}
1048-
10491045
tracePropagationStylesToExtract =
1050-
tracePropagationBehaviorExtract == TracePropagationBehaviorExtract.IGNORE
1051-
? new HashSet<>()
1052-
: extract;
1046+
extract.isEmpty() ? DEFAULT_TRACE_PROPAGATION_STYLE : extract;
10531047

10541048
tracePropagationStylesToInject = inject.isEmpty() ? DEFAULT_TRACE_PROPAGATION_STYLE : inject;
10551049

internal-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,20 +2679,6 @@ class ConfigTest extends DDSpecification {
26792679
config.finalDebuggerSymDBUrl == "http://localhost:8126/symdb/v1/input"
26802680
}
26812681

2682-
def "specify overrides for PROPAGATION_STYLE_EXTRACT when TRACE_PROPAGATION_BEHAVIOR_EXTRACT=ignore"() {
2683-
setup:
2684-
def prop = new Properties()
2685-
prop.setProperty(PROPAGATION_STYLE_EXTRACT, "Datadog, B3")
2686-
prop.setProperty(TRACE_PROPAGATION_BEHAVIOR_EXTRACT, "ignore")
2687-
2688-
when:
2689-
Config config = Config.get(prop)
2690-
2691-
then:
2692-
config.tracePropagationBehaviorExtract == TracePropagationBehaviorExtract.IGNORE
2693-
config.tracePropagationStylesToExtract.toList() == []
2694-
}
2695-
26962682
def "verify try/catch behavior for invalid strings for TRACE_PROPAGATION_BEHAVIOR_EXTRACT"() {
26972683
setup:
26982684
def prop = new Properties()

0 commit comments

Comments
 (0)