feat(sampling): OTel consistent-probability rv/th derivation (APMAPI-2181) - #2276
feat(sampling): OTel consistent-probability rv/th derivation (APMAPI-2181)#2276MilanGarnier wants to merge 12 commits into
Conversation
📚 Documentation Check Results📦
|
🔒 Cargo Deny Results📦
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 984c9f7 | Docs | Datadog PR Page | Give us feedback! |
BenchmarksComparisonBenchmark execution time: 2026-08-03 09:21:07 Comparing candidate commit 984c9f7 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 48 metrics, 10 unstable metrics.
|
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
|
Compute th as round(2^56*(1-rate)) via 2^56 - round(2^56*rate) (exact, avoids the single-shot IEEE-754 rounding the RFC warns against), and return None from otel_consistent_sampling when a probability keep was overturned by the trace rate limiter (rl_effective_rate set).
Use exact integer arithmetic over the canonical 6-decimal rate (the form format_sampling_rate / dd= already use) so th reproduces the RFC imprecision-appendix's decimal table (0.2 -> cccccccccccccd, 0.99 -> 028f5c28f5c28f), which an f64 pipeline cannot represent.
…consistent_sampling
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cce3b2ac43
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99ec5bae75
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…consistent_sampling
…nsistent-sampling
99ec5ba to
984c9f7
Compare
What
Adds a public API to emit OpenTelemetry consistent-probability-sampling tracestate (
ot.th/ot.rv).Part of APMAPI-2170 (OTel consistent probability sampling across dd-trace-*).
Intended for APMAPI-2181 (dd-trace-rs
ot.th/ot.rvwire support);libdatadog's OTLP export (APMAPI-2182) will reuse the same derivation.
Changes
SamplingMechanism::is_probability()— classifies rate-driven mechanisms(DEFAULT, AGENT_RATE_BY_SERVICE, REMOTE_RATE{,_USER,_DATADOG}, the three
*_TRACE_SAMPLING_RULErules) as probability; MANUAL / APPSEC /SPAN_SAMPLING_RULE / DATA_JOBS_MONITORING / OTLP_INGEST_PROBABILISTIC_SAMPLING
as non-probability.
OtelConsistentSampling { rv, th }+TraceRootSamplingInfo::otel_consistent_sampling(trace_id)— returnsSomeonly for a probability decision:
rv = (!(trace_id_low64 * KNUTH_FACTOR)) >> 8(56-bit),th = round(2^56 * (1 - rate_micros / 1_000_000))(56-bit), computed inexact
u128integer arithmetic on the rate rounded to 6 decimals so itmatches the RFC appendix's imprecision table rather than a float
(1.0 - rate) * 2^56. ReturnsNone— erasingthon the wire — both fora non-probability mechanism and for a probability mechanism whose keep was
overturned by the rate limiter (
rl_effective_rate.is_some()); the callerstill forwards an inherited
rvin the latter case. Wire/hex formattingstays tracer-side.
Tests
Tests from system-tests #7372 (rv per trace id; th per the RFC's
exact decimal table at several rates, e.g. 0.01/0.1/0.2/0.5/0.99/1.0;
non-probability -> None; rate-limiter-dropped probability decision -> None).
cargo test -p libdd-sampling: 106 lib + 2 doctests pass. Draft pending thecrate release that dd-trace-rs will pin to.