Skip to content

Commit 67b8312

Browse files
bm1549claude
andcommitted
Add tests for _dd.p.ksr rounding at 6-decimal boundary
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) <[email protected]>
1 parent 422c890 commit 67b8312

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
_dd.p.ksr rounds small rates correctly at 6-decimal boundary
3+
--ENV--
4+
DD_TRACE_SAMPLING_RULES=[{"sample_rate": 0.00000051}]
5+
DD_TRACE_GENERATE_ROOT_SPAN=1
6+
--FILE--
7+
<?php
8+
$root = \DDTrace\root_span();
9+
10+
\DDTrace\get_priority_sampling();
11+
12+
$ksr = isset($root->meta["_dd.p.ksr"]) ? $root->meta["_dd.p.ksr"] : "-";
13+
echo "_dd.p.ksr = ", $ksr, "\n";
14+
// 0.00000051 rounds up to 0.000001 at 6 decimal places
15+
echo "no_sci_notation = ", (strpos($ksr, 'e') === false) ? "true" : "false", "\n";
16+
?>
17+
--EXPECT--
18+
_dd.p.ksr = 0.000001
19+
no_sci_notation = true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
_dd.p.ksr preserves exact 0.000001 rate without rounding away
3+
--ENV--
4+
DD_TRACE_SAMPLING_RULES=[{"sample_rate": 0.000001}]
5+
DD_TRACE_GENERATE_ROOT_SPAN=1
6+
--FILE--
7+
<?php
8+
$root = \DDTrace\root_span();
9+
10+
\DDTrace\get_priority_sampling();
11+
12+
$ksr = isset($root->meta["_dd.p.ksr"]) ? $root->meta["_dd.p.ksr"] : "-";
13+
echo "_dd.p.ksr = ", $ksr, "\n";
14+
echo "no_sci_notation = ", (strpos($ksr, 'e') === false) ? "true" : "false", "\n";
15+
?>
16+
--EXPECT--
17+
_dd.p.ksr = 0.000001
18+
no_sci_notation = true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
_dd.p.ksr rounds rate below 6-decimal precision to 0
3+
--ENV--
4+
DD_TRACE_SAMPLING_RULES=[{"sample_rate": 0.0000001}]
5+
DD_TRACE_GENERATE_ROOT_SPAN=1
6+
--FILE--
7+
<?php
8+
$root = \DDTrace\root_span();
9+
10+
\DDTrace\get_priority_sampling();
11+
12+
$ksr = isset($root->meta["_dd.p.ksr"]) ? $root->meta["_dd.p.ksr"] : "-";
13+
echo "_dd.p.ksr = ", $ksr, "\n";
14+
// 0.0000001 rounds to 0 at 6 decimal places
15+
echo "no_sci_notation = ", (strpos($ksr, 'e') === false) ? "true" : "false", "\n";
16+
?>
17+
--EXPECT--
18+
_dd.p.ksr = 0
19+
no_sci_notation = true

0 commit comments

Comments
 (0)