Skip to content

Commit 3245121

Browse files
committed
Do not allocate a tracing context when not fully extracted
1 parent 456ad68 commit 3245121

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

dd-java-agent/instrumentation/opentelemetry/opentelemetry-1.4/src/test/groovy/opentelemetry14/context/propagation/AbstractPropagatorTest.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import datadog.trace.agent.test.InstrumentationSpecification
44
import datadog.trace.api.DDSpanId
55
import datadog.trace.api.DDTraceId
66
import io.opentelemetry.api.GlobalOpenTelemetry
7+
import io.opentelemetry.api.trace.Span
78
import io.opentelemetry.context.Context
89
import io.opentelemetry.context.ThreadLocalContextStorage
910
import io.opentelemetry.context.propagation.TextMapPropagator
@@ -102,6 +103,14 @@ abstract class AbstractPropagatorTest extends InstrumentationSpecification {
102103
(headers, traceId, spanId, sampling) = values
103104
}
104105

106+
def "extraction on missing tracecontext should return an empty context"() {
107+
when:
108+
def headers = ["User-Agent":"test"]
109+
def context = propagator().extract(Context.root(), headers, TextMap.INSTANCE)
110+
then:
111+
assert Span.fromContextOrNull(context) == null : "Should not have a tracing context"
112+
}
113+
105114
def expectedTraceId(String traceId) {
106115
return DDTraceId.fromHex(traceId)
107116
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public <C> Context extract(Context context, C carrier, CarrierVisitor<C> visitor
6767
}
6868
TagContext spanContext = this.extractor.extract(carrier, toContextVisitor(visitor));
6969
// If the extraction fails, return the original context
70-
if (spanContext == null) {
70+
if (!(spanContext instanceof ExtractedContext)) {
7171
return context;
7272
}
7373
// Otherwise, append a fake span wrapper to context

0 commit comments

Comments
 (0)