Skip to content

test(sampling): widen sampling-rate tolerance to 5 std_dev#7336

Open
bm1549 wants to merge 1 commit into
mainfrom
brian.marks/sampling-rates-widen-tolerance
Open

test(sampling): widen sampling-rate tolerance to 5 std_dev#7336
bm1549 wants to merge 1 commit into
mainfrom
brian.marks/sampling-rates-widen-tolerance

Conversation

@bm1549

@bm1549 bm1549 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Motivation

Test_SamplingRates.test_sampling_rates sends 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-jetty and jersey-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.

band per run per day (~6.5k runs) per year
±4 std_dev (before) ~6e-5 ~0.4 ~150
±5 std_dev (after) ~6e-7 ~0.004 ~1

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:

Those catch subtle drift; a persistent rate bias is still caught here. Widening the aggregate band doesn't lose that coverage.

Workflow

  1. ⚠️ Create your PR as draft ⚠️
  2. Work on you PR until the CI passes
  3. Mark it as ready for review
    • Test logic is modified? -> Get a review from RFC owner.
    • Framework is modified, or non obvious usage of it -> get a review from R&P team

🚀 Once your PR is reviewed and the CI green, you can merge it!

🛟 #apm-shared-testing 🛟

Reviewer checklist

  • Anything but tests/ or manifests/ is modified ? — No, only tests/test_sampling_rates.py.
  • A docker base image is modified? — No.
    • the relevant build-XXX-image label is present
  • A scenario is added, removed or renamed? — No.

🤖 Generated with Claude Code

@bm1549 bm1549 added the ai-generated The pull request includes a significant amount of AI-generated code label Jul 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

CODEOWNERS have been resolved as:

tests/test_sampling_rates.py                                            @DataDog/system-tests-core

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Jul 17, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 4277cd2 | Docs | Datadog PR Page | Give us feedback!

@bm1549
bm1549 force-pushed the brian.marks/sampling-rates-widen-tolerance branch 3 times, most recently from ae32765 to d0ba1c9 Compare July 17, 2026 14:45
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
bm1549 force-pushed the brian.marks/sampling-rates-widen-tolerance branch from d0ba1c9 to 4277cd2 Compare July 17, 2026 14:50
@bm1549
bm1549 marked this pull request as ready for review July 17, 2026 18:39
@bm1549
bm1549 requested a review from a team as a code owner July 17, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated The pull request includes a significant amount of AI-generated code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant