Commit f657b07
fix(tracing): format _dd.p.ksr with decimal notation instead of scientific notation (#7846)
* fix(tracing): format _dd.p.ksr with decimal notation instead of scientific notation
Very small sampling rates (e.g. 0.0000001) were formatted using
toPrecision(6) + toString() which outputs scientific notation like
"1e-7". This changes to explicit rounding at the integer level and
toFixed(6) 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) <[email protected]>
* fix(tracing): replace regex with loop in formatKnuthRate for hot-path perf
Addresses PR review feedback: replaces the regex-based trailing-zero
strip with a manual loop to avoid regex overhead on the hot path.
Also adds Number() coercion as defensive measure per reviewer suggestion.
Math.round pre-rounding is intentionally kept — toFixed(6) has imprecise
rounding for sub-precision values in V8 (e.g. 0.0000005.toFixed(6)
returns '0.000000' in Node 23). JSDoc updated to explain this.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* fix(tracing): simplify formatKnuthRate loop per review feedback
Drop Math.round pre-rounding — the edge case (0.0000005 rounding down in
V8) is acceptable imprecision. Test updated to use 0.00000051 which rounds
up unambiguously without Math.round.
Drop indexOf('.') — check for '.' directly in the loop instead, which
handles integer rates (0, 1) without the overhead of a separate scan.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* Update packages/dd-trace/src/priority_sampler.js
Co-authored-by: Ruben Bridgewater <[email protected]>
* fix(tracing): resolve lint errors in formatKnuthRate
- Flip negated conditions to positive checks (unicorn/no-negated-condition)
- Remove @returns tag since linter can't statically verify loop always returns (jsdoc/require-returns-check)
- Preserve BridgeAR's single-check-per-iteration optimization
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Ruben Bridgewater <[email protected]>1 parent da201ff commit f657b07
File tree
2 files changed
+45
-3
lines changed- packages/dd-trace
- src
- test
2 files changed
+45
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
424 | 463 | | |
425 | 464 | | |
426 | 465 | | |
| |||
0 commit comments