fix(sampling): record rate limiter's effective rate on allow, not just drop - #2288
Conversation
BenchmarksComparisonBenchmark execution time: 2026-07-30 16:23:09 Comparing candidate commit 5117c2b in PR branch Found 4 performance improvements and 2 performance regressions! Performance is the same for 42 metrics, 10 unstable metrics.
|
…t drop dd-trace-rb and dd-trace-go both stamp the rate limiter's effective rate unconditionally once the limiter is consulted, regardless of allow/drop. libdatadog only recorded it on drop, diverging from other tracers.
286da37 to
c01edb8
Compare
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 5117c2b | 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
|
What
DatadogSampler::sample_rootonly recordedrl_effective_rate(the ratelimiter's effective accept rate, wired as
_dd.limit_psr) when the ratelimiter dropped a trace. It should be recorded whenever the limiter is
consulted, regardless of outcome.
Why this doesn't follow other tracers
rule_sampler.rb,apply_rule!): callsrate_limiter.allow?.tap { |allowed| ... set_limiter_metrics(trace, rate_limiter.effective_rate) ... }— the effective rate is set inside the.tapblock unconditionally, for bothallowed == trueandfalse.span.go): callslimiter.AllowOne(now)and then alwayscalls
setMetricLocked(keyRulesSamplerLimiterRate, limiterRate)rightafter, independent of the allow/drop outcome.
libdatadog:
_dd.limit_psrwas only emitted onrate-limiter-drop, silently omitting it on allow. This matters for the
Datadog Agent's stats extrapolation (
1/psr), which needs the tag wheneverthe limiter was in play, not just when it rejected the trace.
Change
sample_root: once a rule matches and keeps the trace, always callself.rate_limiter.effective_rate()afteris_allowed(), whether or notthe limiter allowed it.
Tests
cargo test -p libdd-sampling: 104 lib + 2 doctests pass. fmt and clippyclean.