fix(libdd-trace-utils): apply SpanLink flags masking when v0.5 json encoding - #2314
Conversation
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 3e02c48 | Docs | Datadog PR Page | Give us feedback! |
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
BenchmarksComparisonBenchmark execution time: 2026-08-05 16:40:39 Comparing candidate commit 3e02c48 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 139 metrics, 0 unstable metrics.
|
bwoebi
left a comment
There was a problem hiding this comment.
Looks correct to me, thanks for the improvement.
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
What does this PR do?
A tracer flags a
SpanLinkwith a 32-bit flags value. Bit 31 is a sentinel: it marks that the tracer explicitly set the sampling decision, as opposed to leavingflagsat its default of zero. The remaining bits carry the sampling decision itself (bit 0: kept or dropped).Motivation
v0.4 and v0.5 disagree on whether the wire value includes this sentinel.
0x8000_0001; a link the tracer explicitly dropped becomes0x8000_0000.meta["_dd.span_links"]. dd-trace-py's v0.5 JSON encoder never adds the sentinel. A kept link's flags in this JSON is plain 1; the sentinel bit never appears there.libdatadog's v0.5 encoder builds this JSON from the same
SpanLinkstruct that v0.4 uses, so flags may already carry the sentinel bit. Before this fix, the v0.5 serializer wrote that raw value straight into the JSON, so a kept link produced"flags": 2147483649instead of1— a value no v0.5 producer would ever emit, and one that downstream consumers checking against small integers would not recognize as "kept".This PR masks bit 31 off the value the v0.5 serializer writes into flags, while it still decides whether to emit the flags key at all from the raw, unmasked value. Deciding presence from the masked value would break the case of a link the tracer explicitly dropped: raw
0x8000_0000masks to0, indistinguishable from "flags never set" if presence were decided post-mask. With this fix, an explicitly dropped link still emits"flags": 0; a link that never set flags emits no flags key at all.Additional Notes
Anything else we should know when reviewing?
How to test the change?
span_link_flags_sentinel_bit_masked_test: covers the unset, kept, and explicitly-dropped states of the sentinel bit.cargo test -p libdd-trace-utils,cargo fmt --check, andcargo clippy -D warningspass.