Skip to content

Fix printing format of span identifiers #8897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static datadog.trace.api.cache.RadixTreeCache.HTTP_STATUSES;
import static datadog.trace.bootstrap.instrumentation.api.ErrorPriorities.UNSET;

import datadog.trace.api.DDSpanId;
import datadog.trace.api.DDTags;
import datadog.trace.api.DDTraceId;
import datadog.trace.api.Functions;
Expand Down Expand Up @@ -892,9 +893,9 @@ public String toString() {
.append("DDSpan [ t_id=")
.append(traceId)
.append(", s_id=")
.append(spanId)
.append(DDSpanId.toString(spanId))
.append(", p_id=")
.append(parentId)
.append(DDSpanId.toString(parentId))
.append(" ] trace=")
.append(getServiceName())
.append('/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import static datadog.trace.core.DDSpanContext.SPAN_SAMPLING_MAX_PER_SECOND_TAG
class DDSpanContextTest extends DDCoreSpecification {

def writer
def tracer
CoreTracer tracer
def profilingContextIntegration

def setup() {
Expand Down Expand Up @@ -289,6 +289,29 @@ class DDSpanContextTest extends DDCoreSpecification {
"_dd.${tag}.json"
}

def "Span IDs printed as unsigned long"() {
setup:
def parent = tracer.buildSpan("fakeOperation")
.withServiceName("fakeService")
.withResourceName("fakeResource")
.withSpanId(-987654321)
.start()

def span = tracer.buildSpan("fakeOperation")
.withServiceName("fakeService")
.withResourceName("fakeResource")
.withSpanId(-123456789)
.asChildOf(parent.context())
.start()

def context = span.context() as DDSpanContext

expect:
// even though span ID and parent ID are setup as negative numbers, they should be printed as their unsigned value
// asserting there is no negative sign after ids is the best I can do.
context.toString().contains("id=-") == false
}

static void assertTagmap(Map source, Map comparison, boolean removeThread = false) {
def sourceWithoutCommonTags = new HashMap(source)
sourceWithoutCommonTags.remove("runtime-id")
Expand Down