Skip to content

Commit 625a498

Browse files
committed
remove sampling priority argument from the trace parent util
1 parent 8d93099 commit 625a498

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@ private W3CTraceParent() {}
2323
*
2424
* @param traceId the trace id
2525
* @param spanId the span id
26-
* @param samplingPriority the sampling priority (positive values result in sampled flag set)
26+
* @param isSampled whether the trace was sampled or not
2727
* @return the W3C traceparent header value
2828
*/
29-
public static String from(DDTraceId traceId, long spanId, int samplingPriority) {
29+
public static String from(DDTraceId traceId, long spanId, boolean isSampled) {
3030
StringBuilder sb = new StringBuilder(TRACE_PARENT_LENGTH);
3131
sb.append("00-");
3232
sb.append(traceId.toHexString());
3333
sb.append('-');
3434
sb.append(DDSpanId.toHexStringPadded(spanId));
35-
sb.append(samplingPriority > 0 ? "-01" : "-00");
35+
sb.append(isSampled ? "-01" : "-00");
3636

3737
return sb.toString();
3838
}
3939

4040
public static String from(AgentSpan span) {
41-
return from(span.getTraceId(), span.getSpanId(), span.context().getSamplingPriority());
41+
return from(span.getTraceId(), span.getSpanId(), span.context().getSamplingPriority() > 0);
4242
}
4343

4444
public static String from(DDSpanContext spanContext) {
4545
return from(
46-
spanContext.getTraceId(), spanContext.getSpanId(), spanContext.getSamplingPriority());
46+
spanContext.getTraceId(), spanContext.getSpanId(), spanContext.getSamplingPriority() > 0);
4747
}
4848
}

dd-trace-core/src/test/groovy/datadog/trace/core/propagation/W3CTraceParentTest.groovy

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@ import datadog.trace.test.util.DDSpecification
55

66
class W3CTraceParentTest extends DDSpecification {
77

8-
def "build produces correct format with samplingPriority=#samplingPriority"() {
8+
def "build produces correct format with isSampled=#isSampled"() {
99
when:
10-
def result = W3CTraceParent.from(traceId, spanId, samplingPriority)
10+
def result = W3CTraceParent.from(traceId, spanId, isSampled)
1111

1212
then:
1313
result == expected
1414

1515
where:
16-
traceId | spanId | samplingPriority | expected
17-
DDTraceId.from(1) | 2 | 1 | "00-00000000000000000000000000000001-0000000000000002-01"
18-
DDTraceId.from(1) | 2 | 0 | "00-00000000000000000000000000000001-0000000000000002-00"
19-
DDTraceId.from(1) | 2 | -1 | "00-00000000000000000000000000000001-0000000000000002-00"
20-
DDTraceId.from(1) | 2 | 2 | "00-00000000000000000000000000000001-0000000000000002-01"
21-
DDTraceId.fromHex("0af7651916cd43dd8448eb211c80319c") | 0x00f067aa0ba902b7L | 1 | "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01"
22-
DDTraceId.from(Long.MAX_VALUE) | Long.MAX_VALUE | 1 | "00-00000000000000007fffffffffffffff-7fffffffffffffff-01"
16+
traceId | spanId | isSampled | expected
17+
DDTraceId.from(1) | 2 | true | "00-00000000000000000000000000000001-0000000000000002-01"
18+
DDTraceId.from(1) | 2 | false | "00-00000000000000000000000000000001-0000000000000002-00"
19+
DDTraceId.from(1) | 2 | true | "00-00000000000000000000000000000001-0000000000000002-01"
20+
DDTraceId.fromHex("0af7651916cd43dd8448eb211c80319c") | 0x00f067aa0ba902b7L | true | "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01"
21+
DDTraceId.from(Long.MAX_VALUE) | Long.MAX_VALUE | true | "00-00000000000000007fffffffffffffff-7fffffffffffffff-01"
2322
}
2423

2524
def "build matches W3C traceparent format"() {
2625
when:
27-
def result = W3CTraceParent.from(DDTraceId.from(123456789L), 987654321L, 1)
26+
def result = W3CTraceParent.from(DDTraceId.from(123456789L), 987654321L, true)
2827

2928
then:
3029
// W3C format: version-traceId(32 hex)-spanId(16 hex)-flags(2 hex)

0 commit comments

Comments
 (0)