10000 Fix printing format of span identifiers (#8897) · DataDog/dd-trace-java@3070e2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3070e2e

Browse files
Fix printing format of span identifiers (#8897)
* fix printing format of span IDs * use DDSpanID.toString Co-authored-by: Bruce Bujon <PerfectSlayer@users.noreply.github.com> * use DDSpanID.toString Co-authored-by: Bruce Bujon <PerfectSlayer@users.noreply.github.com> * add test * fix build * fix test name --------- Co-authored-by: Bruce Bujon <PerfectSlayer@users.noreply.github.com>
1 parent 3b2874e commit 3070e2e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static datadog.trace.api.cache.RadixTreeCache.HTTP_STATUSES;
66
import static datadog.trace.bootstrap.instrumentation.api.ErrorPriorities.UNSET;
77

8+
import datadog.trace.api.DDSpanId;
89
import datadog.trace.api.DDTags;
910
import datadog.trace.api.DDTraceId;
1011
import datadog.trace.api.Functions;
@@ -892,9 +893,9 @@ public String toString() {
892893
.append("DDSpan [ t_id=")
893894
.append(traceId)
894895
.append(", s_id=")
895-
.append(spanId)
896+
.append(DDSpanId.toString(spanId))
896897
.append(", p_id=")
897-
.append(parentId)
898+
.append(DDSpanId.toString(parentId))
898899
.append(" ] trace=")
899900
.append(getServiceName())
900901
.append('/')

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import static datadog.trace.core.DDSpanContext.SPAN_SAMPLING_MAX_PER_SECOND_TAG
1919
class DDSpanContextTest extends DDCoreSpecification {
2020

2121
def writer
22-
def tracer
22+
CoreTracer tracer
2323
def profilingContextIntegration
2424

2525
def setup() {
@@ -289,6 +289,29 @@ class DDSpanContextTest extends DDCoreSpecification {
289289
"_dd.${tag}.json"
290290
}
291291

292+
def "Span IDs printed as unsigned long"() {
293+
setup:
294+
def parent = tracer.buildSpan("fakeOperation")
295+
.withServiceName("fakeService")
296+
.withResourceName("fakeResource")
297+
.withSpanId(-987654321)
298+
.start()
299+
300+
def span = tracer.buildSpan("fakeOperation")
301+
.withServiceName("fakeService")
302+
.withResourceName("fakeResource")
303+
.withSpanId(-123456789)
304+
.asChildOf(parent.context())
305+
.start()
306+
307+
def context = span.context() as DDSpanContext
308+
309+
expect:
310+
// even though span ID and parent ID are setup as negative numbers, they should be printed as their unsigned value
311+
// asserting there is no negative sign after ids is the best I can do.
312+
context.toString().contains("id=-") == false
313+
}
314+
292315
static void assertTagmap(Map source, Map comparison, boolean removeThread = false) {
293316
def sourceWithoutCommonTags = new HashMap(source)
294317
sourceWithoutCommonTags.remove("runtime-id")

0 commit comments

Comments
 (0)
0