Skip to content

Fix span link span ID hex padding - #12279

Open
itsamenathan wants to merge 2 commits into
DataDog:masterfrom
itsamenathan:fix/pad-span-link-span-id-hex
Open

Fix span link span ID hex padding#12279
itsamenathan wants to merge 2 commits into
DataDog:masterfrom
itsamenathan:fix/pad-span-link-span-id-hex

Conversation

@itsamenathan

Copy link
Copy Markdown

What Does This Do

Pads the span_id field emitted in the _dd.span_links tag to 16 hex
characters, matching the existing padding behavior of trace_id.

Motivation

DDSpanLink serializes span link ids using DDTraceId.toHexString() for
the trace id, which is zero-padded to 32 characters, but
DDSpanId.toHexString() for the span id, which delegates to
Long.toHexString and strips leading zeros. Since span ids are generated
as non-zero positive longs, about 1 in 16 span ids has a zero leading
nibble and serializes to 15 characters instead of 16.

Consumers that parse this field as fixed-width hex reject it: the
OpenTelemetry Collector's Datadog receiver calls SpanIDFromHex, which
requires exactly 16 characters, and drops the link. trace_id is
unaffected because both DD64bTraceId and DD128bTraceId already pad
to 32.

Additional Notes

Uses DDSpanId.toHexStringPadded, an existing padded variant already on
the same class, rather than changing DDSpanId.toHexString itself —
that method is a separate shared utility used elsewhere (e.g. B3 header
encoding, trace export JSON) where the unpadded form is intentional and
tested.

DDSpanLink serialises link ids into the _dd.span_links tag with
DDTraceId.toHexString for the trace id, which pads to 32 characters, but
DDSpanId.toHexString for the span id, which delegates to
Long.toHexString and strips leading zeros.

Span ids are generated as non-zero positive longs, so the leading hex
nibble is zero for one id in eight and those ids serialise to 15
characters or fewer. Consumers that treat the field as fixed-width hex
reject them: the OpenTelemetry Collector's Datadog receiver calls
SpanIDFromHex, which requires exactly 16 characters, and drops the link.
The trace id is unaffected because both DD64bTraceId and DD128bTraceId
pad to 32.

Use DDSpanId.toHexStringPadded, which is the existing padded variant on
the same class, so the emitted id is always 16 characters.
@itsamenathan
itsamenathan requested a review from a team as a code owner August 24, 2026 22:03
@itsamenathan
itsamenathan requested review from AlexeyKuznetsov-DD and removed request for a team August 24, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant