test(sampling): widen sampling-rate tolerance to 5 std_dev#7336
Open
bm1549 wants to merge 1 commit into
Open
Conversation
Contributor
|
|
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 4277cd2 | Docs | Datadog PR Page | Give us feedback! |
bm1549
force-pushed
the
brian.marks/sampling-rates-widen-tolerance
branch
3 times, most recently
from
July 17, 2026 14:45
ae32765 to
d0ba1c9
Compare
Test_SamplingRates.test_sampling_rates asserts the tracer's kept-trace count lands within a tolerance band of the expected count. The band was 4 std_dev (~6e-5 false-positive rate per run). This assertion runs thousands of times per day across every tracer/weblog variant, so at 4 std_dev it produced ~150 statistical false failures per year fleet-wide. Widen to 5 std_dev (~6e-7/run, ~1/year fleet-wide) and correct the comment and failure message, which claimed a "95% confidence interval" and "should fail ~5% of the time" — both wrong for a 4 std_dev band (~99.99%, ~0.006%). Delivery assertion (assert_all_traces_requests_forwarded) is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bm1549
force-pushed
the
brian.marks/sampling-rates-widen-tolerance
branch
from
July 17, 2026 14:50
d0ba1c9 to
4277cd2
Compare
bm1549
marked this pull request as ready for review
July 17, 2026 18:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Test_SamplingRates.test_sampling_ratessends 2000 requests to a tracer sampling at 50% and checks the kept-trace count lands within a ±k·std_dev band of the expected count. The band was ±4 std_dev.The kept count is
Binomial(n, p), so a correctly-sampling tracer falls outside ±4 std_dev about 6e-5 of the time. This assertion runs ~6,500 times/day across all tracers and weblogs (per CI Visibility), so ±4 std_dev meant a correct tracer failed it purely by chance ~0.4 times/day, ~150/year. Real recent examples on default branches:apache-mod-8.1(php),spring-boot-jettyandjersey-grizzly2(java), three in the last 90 days, each a ~4σ tail landing on both sides of 50%.The comment and message were also wrong. The comment called a ±4 std_dev band a "95% confidence interval" (95% is ~1.96 std_dev), and the message said the test "should fail ~5% of the time" when the real rate was ~0.006%.
Changes
Widen the band to ±5 std_dev and correct the comment and failure message.
TOTAL_REQUESTS(2000) and the delivery assertion (assert_all_traces_requests_forwarded) are unchanged.This test is a backstop for severe sampling regressions, not the exact-correctness check. Per-decision correctness is already verified deterministically, using the same Knuth formula, by:
Test_SamplingDecision.test_sampling_decision— every root span's decision must equaltrace_should_be_kept(rate, trace_id).Test_SampleRateFunction.test_sample_rate_function— fixed(trace_id → expected decision)fixtures fromtests/fixtures/sampling_rates.csv.Those catch subtle drift; a persistent rate bias is still caught here. Widening the aggregate band doesn't lose that coverage.
Workflow
🚀 Once your PR is reviewed and the CI green, you can merge it!
🛟 #apm-shared-testing 🛟
Reviewer checklist
tests/ormanifests/is modified ? — No, onlytests/test_sampling_rates.py.build-XXX-imagelabel is present🤖 Generated with Claude Code