You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(libdd-trace-utils): apply SpanLink flags masking when v0.5 json encoding (#2314)
# What does this PR do?
A tracer flags a `SpanLink` with a 32-bit flags value. Bit 31 is a sentinel: it marks that the tracer explicitly set the sampling decision, as opposed to leaving `flags` at 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.
- In v0.4's native msgpack encoding, dd-trace-py adds the sentinel bit before it writes flags. A kept link becomes `0x8000_0001`; a link the tracer explicitly dropped becomes `0x8000_0000`.
- v0.5 has no native span-link field, so it encodes links as a JSON array under `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 `SpanLink` struct 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": 2147483649` instead of `1` — 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_0000` masks to `0`, 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?
- Added `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`, and `cargo clippy -D warnings` pass.
Co-authored-by: bob.weinand <bob.weinand@datadoghq.com>
0 commit comments