Skip to content

Commit 13b7d5e

Browse files
bm1549claude
andcommitted
fix: add ksr and tid handling to OpenTracing31Test inject extract
Update the test inject extract expectations to include _dd.p.ksr=1 in x-datadog-tags and t.ksr:1 in tracestate for the UNSET sampling case, following PTagsCodec ordering: dm -> tid -> ksr. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b46e9de commit 13b7d5e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

dd-java-agent/instrumentation/opentracing/opentracing-0.31/src/test/groovy/OpenTracing31Test.groovy

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,30 @@ class OpenTracing31Test extends InstrumentationSpecification {
284284
"-${DDSpanId.toHexStringPadded(context.delegate.spanId)}" +
285285
"-" + (propagatedPriority > 0 ? "01" : "00")
286286
def expectedTracestate = "dd=s:${propagatedPriority};p:${DDSpanId.toHexStringPadded(context.delegate.spanId)}"
287-
def expectedDatadogTags = null
287+
def datadogTags = []
288288
if (propagatedPriority > 0) {
289289
def effectiveSamplingMechanism = contextPriority == UNSET ? AGENT_RATE : samplingMechanism
290-
expectedDatadogTags = "_dd.p.dm=-" + effectiveSamplingMechanism
291-
expectedTracestate+= ";t.dm:-" + effectiveSamplingMechanism
290+
datadogTags << "_dd.p.dm=-" + effectiveSamplingMechanism
291+
expectedTracestate += ";t.dm:-" + effectiveSamplingMechanism
292+
}
293+
def traceId = context.delegate.traceId as DDTraceId
294+
if (traceId.toHighOrderLong() != 0) {
295+
expectedTracestate += ";t.tid:${traceId.toHexStringPadded(32).substring(0, 16)}"
296+
datadogTags << "_dd.p.tid=" + traceId.toHexStringPadded(32).substring(0, 16)
297+
}
298+
if (contextPriority == UNSET) {
299+
expectedTracestate += ";t.ksr:1"
300+
datadogTags << "_dd.p.ksr=1"
292301
}
293-
294302
def expectedTextMap = [
295303
"x-datadog-trace-id" : "$context.delegate.traceId",
296304
"x-datadog-parent-id" : "$context.delegate.spanId",
297305
"x-datadog-sampling-priority": propagatedPriority.toString(),
298306
"traceparent" : expectedTraceparent,
299307
"tracestate" : expectedTracestate,
300308
]
301-
if (expectedDatadogTags != null) {
302-
expectedTextMap.put("x-datadog-tags", expectedDatadogTags)
309+
if (!datadogTags.empty) {
310+
expectedTextMap.put("x-datadog-tags", datadogTags.join(','))
303311
}
304312
textMap == expectedTextMap
305313

0 commit comments

Comments
 (0)