Skip to content

Fix _dd.p.ksr scientific notation for very small sampling rates#3721

Merged
bm1549 merged 4 commits intomasterfrom
brian.marks/fix-ksr-scientific-notation
Mar 25, 2026
Merged

Fix _dd.p.ksr scientific notation for very small sampling rates#3721
bm1549 merged 4 commits intomasterfrom
brian.marks/fix-ksr-scientific-notation

Conversation

@bm1549
Copy link
Copy Markdown
Contributor

@bm1549 bm1549 commented Mar 24, 2026

Description

Fix _dd.p.ksr span tag formatting for very small sampling rates. Rates below 0.001 were formatted using C's %.6g format which outputs scientific notation (e.g. 0.000001"1e-06"). Changed to explicit integer-level rounding via floor(rate * 1e6 + 0.5) and %.6f formatting to always produce decimal notation with up to 6 decimal digits, trailing zeros stripped.

Fixes APMAPI-1869

Related PRs:

Testing

  • Updated test description in tests/ext/priority_sampling/028-ksr-tag-formatting.phpt
  • Added new test tests/ext/priority_sampling/029-ksr-tag-small-rate-formatting.phpt verifying:
    • Rate 0.000001 → "0.000001" (decimal notation, not "1e-06")
    • No scientific notation characters in output

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

Very small sampling rates (e.g. 0.000001) were formatted using C's
%.6g format which outputs scientific notation like "1e-06". This changes
to explicit rounding at the integer level via floor(x * 1e6 + 0.5) and
%.6f formatting to always produce decimal notation with up to 6 decimal
digits, trailing zeros stripped (e.g. "0.000001").

Fixes APMAPI-1869

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bm1549 bm1549 added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Mar 24, 2026
@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 bot commented Mar 24, 2026

⚠️ Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

❄️ 10 New flaky tests detected

tmp/build_extension/tests/ext/priority_sampling/028-ksr-tag-formatting.phpt (_dd.p.ksr propagated tag formats rate with up to 6 decimal digits and no trailing zeros) from PHP.tmp.build_extension.tests.ext.priority_sampling   View in Datadog   (Fix with Cursor)
001+ _dd.p.ksr = -
002+ is_string = false
001- _dd.p.ksr = 0.765432
002- is_string = true
tmp/build_extension/tests/ext/priority_sampling/029-ksr-tag-small-rate-formatting.phpt (_dd.p.ksr uses decimal notation (not scientific) for very small sampling rates) from PHP.tmp.build_extension.tests.ext.priority_sampling   View in Datadog   (Fix with Cursor)
001+ _dd.p.ksr = -
001- _dd.p.ksr = 0.000001
     no_sci_notation = true
tmp/build_extension/tests/ext/priority_sampling/030-ksr-tag-rounding-boundary.phpt (_dd.p.ksr rounds small rates correctly at 6-decimal boundary) from PHP.tmp.build_extension.tests.ext.priority_sampling   View in Datadog   (Fix with Cursor)
001+ _dd.p.ksr = -
001- _dd.p.ksr = 0.000001
     no_sci_notation = true
View all

🧪 1056 Tests failed

testSearchPhpBinaries from integration.DDTrace\Tests\Integration\PHPInstallerTest   View in Datadog   (Fix with Cursor)
DDTrace\Tests\Integration\PHPInstallerTest::testSearchPhpBinaries
Test code or tested code printed unexpected output: Searching for available php binaries, this operation might take a while.
testSimplePushAndProcess from laravel-58-test.DDTrace\Tests\Integrations\Laravel\V5_8\QueueTest   View in Datadog   (Fix with Cursor)
DDTrace\Tests\Integrations\Laravel\V5_8\QueueTest::testSimplePushAndProcess
Test code or tested code printed unexpected output: spanLinksTraceId: 69c3fd3e000000006ebd1f45a05e5f74
tid: 69c3fd3e00000000
hexProcessTraceId: 6ebd1f45a05e5f74
hexProcessSpanId: 57ff2a7a8b780a8b
processTraceId: 7979568498674130804
processSpanId: 6340833506175224459

phpvfscomposer://tests/vendor/phpunit/phpunit/phpunit:106
testSimplePushAndProcess from laravel-8x-test.DDTrace\Tests\Integrations\Laravel\V8_x\QueueTest   View in Datadog   (Fix with Cursor)
DDTrace\Tests\Integrations\Laravel\V8_x\QueueTest::testSimplePushAndProcess
Test code or tested code printed unexpected output: spanLinksTraceId: 69c3fd7100000000dbd7a407e1981b36
tid: 69c3fd7100000000
hexProcessTraceId: dbd7a407e1981b36
hexProcessSpanId: df425d8e8b020e84
processTraceId: 15841310568055577398
processSpanId: 16087523685719740036
View all

ℹ️ Info

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 60.63% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 67b8312 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.74%. Comparing base (55eb9e5) to head (67b8312).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3721      +/-   ##
==========================================
+ Coverage   68.73%   68.74%   +0.01%     
==========================================
  Files         166      166              
  Lines       19030    19030              
  Branches     1797     1797              
==========================================
+ Hits        13080    13082       +2     
+ Misses       5135     5132       -3     
- Partials      815      816       +1     
Flag Coverage Δ
helper-rust-integration 78.82% <ø> (ø)
helper-rust-unit 49.36% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55eb9e5...67b8312. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bm1549 bm1549 marked this pull request as ready for review March 24, 2026 01:43
@bm1549 bm1549 requested a review from a team as a code owner March 24, 2026 01:43
bm1549 and others added 3 commits March 24, 2026 07:01
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Test three boundary cases for small sampling rates:
- 0.00000051 rounds up to 0.000001
- 0.000001 stays exactly 0.000001
- 0.0000001 rounds down to 0

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 25, 2026

Benchmarks [ tracer ]

Benchmark execution time: 2026-03-25 16:29:33

Comparing candidate commit 67b8312 in PR branch brian.marks/fix-ksr-scientific-notation with baseline commit 55eb9e5 in branch master.

Found 0 performance improvements and 8 performance regressions! Performance is the same for 184 metrics, 2 unstable metrics.

scenario:ContextPropagationBench/benchInject64Bit

  • 🟥 execution_time [+55.226ns; +146.774ns] or [+2.517%; +6.690%]

scenario:ContextPropagationBench/benchInject64Bit-opcache

  • 🟥 execution_time [+84.368ns; +205.632ns] or [+3.877%; +9.450%]

scenario:MessagePackSerializationBench/benchMessagePackSerialization

  • 🟥 execution_time [+4.041µs; +5.239µs] or [+4.128%; +5.350%]

scenario:MessagePackSerializationBench/benchMessagePackSerialization-opcache

  • 🟥 execution_time [+5.844µs; +6.956µs] or [+5.745%; +6.839%]

scenario:SamplingRuleMatchingBench/benchGlobMatching2-opcache

  • 🟥 execution_time [+58.089ns; +184.111ns] or [+2.245%; +7.116%]

scenario:SamplingRuleMatchingBench/benchGlobMatching3-opcache

  • 🟥 execution_time [+70.363ns; +239.237ns] or [+2.588%; +8.798%]

scenario:SamplingRuleMatchingBench/benchRegexMatching1

  • 🟥 execution_time [+37.049ns; +113.951ns] or [+2.531%; +7.784%]

scenario:SamplingRuleMatchingBench/benchRegexMatching2

  • 🟥 execution_time [+34.800ns; +115.800ns] or [+2.342%; +7.794%]

@bm1549 bm1549 merged commit 116d0de into master Mar 25, 2026
2098 checks passed
@bm1549 bm1549 deleted the brian.marks/fix-ksr-scientific-notation branch March 25, 2026 17:23
@github-actions github-actions bot added this to the 1.18.0 milestone Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants