Skip to content

fix(tracing): format _dd.p.ksr with decimal notation instead of scientific notation#7846

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

fix(tracing): format _dd.p.ksr with decimal notation instead of scientific notation#7846
bm1549 merged 6 commits intomasterfrom
brian.marks/fix-ksr-scientific-notation

Conversation

@bm1549
Copy link
Copy Markdown
Contributor

@bm1549 bm1549 commented Mar 24, 2026

What does this PR do?

Fix _dd.p.ksr span tag formatting for very small sampling rates. Rates below 0.0000001 were formatted using toPrecision(6) + toString() which outputs scientific notation (e.g. 0.0000001"1e-7").

The formatKnuthRate function now uses toFixed(6) for decimal notation, with a loop to strip trailing zeros (replacing a regex for hot-path performance). The loop checks for '.' explicitly to correctly handle integer rates like 0 and 1.

Motivation

Fixes APMAPI-1869. System tests expect decimal notation for _dd.p.ksr values (see DataDog/system-tests#6466).

Related PRs:

Additional Notes

All 10 priority_sampler tests pass. Added 3 new test cases for small-rate formatting:

  • Rate 0.000001 → "0.000001" (decimal notation)
  • Rate 0.0000001 → "0" (rounds to zero)
  • Rate 0.00000051 → "0.000001" (rounds up)

Addressed review feedback from @BridgeAR:

  • Added Number() coercion as defensive measure
  • Replaced regex trailing-zero strip with a loop that checks for '.' inline (no indexOf overhead)
  • Dropped Math.round pre-rounding per reviewer preference; test value updated to 0.00000051 (unambiguously above halfway point)

…tific 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]>
@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
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.45%. Comparing base (b90857d) to head (ec8b672).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7846      +/-   ##
==========================================
- Coverage   80.45%   80.45%   -0.01%     
==========================================
  Files         749      749              
  Lines       32479    32482       +3     
==========================================
+ Hits        26130    26132       +2     
- Misses       6349     6350       +1     
Flag Coverage Δ
aiguard-macos 39.14% <100.00%> (-0.08%) ⬇️
aiguard-ubuntu 39.25% <100.00%> (-0.08%) ⬇️
aiguard-windows 38.95% <100.00%> (-0.08%) ⬇️
apm-capabilities-tracing-macos 48.92% <100.00%> (-0.04%) ⬇️
apm-capabilities-tracing-ubuntu 49.00% <100.00%> (+<0.01%) ⬆️
apm-capabilities-tracing-windows 48.73% <100.00%> (-0.01%) ⬇️
apm-integrations-child-process 38.48% <100.00%> (-0.08%) ⬇️
apm-integrations-couchbase-18 37.32% <100.00%> (-0.08%) ⬇️
apm-integrations-couchbase-eol 37.80% <100.00%> (-0.08%) ⬇️
apm-integrations-oracledb 37.64% <100.00%> (-0.08%) ⬇️
appsec-express 55.14% <100.00%> (-0.06%) ⬇️
appsec-fastify 51.50% <100.00%> (-0.06%) ⬇️
appsec-graphql 51.66% <100.00%> (-0.07%) ⬇️
appsec-kafka 44.28% <100.00%> (-0.07%) ⬇️
appsec-ldapjs 43.90% <100.00%> (-0.07%) ⬇️
appsec-lodash 43.51% <0.00%> (-0.09%) ⬇️
appsec-macos 58.17% <100.00%> (-0.06%) ⬇️
appsec-mongodb-core 48.56% <100.00%> (-0.19%) ⬇️
appsec-mongoose 49.32% <100.00%> (-0.07%) ⬇️
appsec-mysql 50.86% <100.00%> (+0.03%) ⬆️
appsec-node-serialize 43.09% <100.00%> (-0.07%) ⬇️
appsec-passport 47.52% <100.00%> (-0.07%) ⬇️
appsec-postgres 50.49% <100.00%> (-0.06%) ⬇️
appsec-sourcing 42.51% <100.00%> (-0.07%) ⬇️
appsec-stripe 44.52% <100.00%> (-0.07%) ⬇️
appsec-template 43.25% <100.00%> (-0.07%) ⬇️
appsec-ubuntu 58.24% <100.00%> (-0.06%) ⬇️
appsec-windows 58.01% <100.00%> (-0.06%) ⬇️
instrumentations-instrumentation-bluebird 32.23% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-body-parser 40.42% <100.00%> (-0.08%) ⬇️
instrumentations-instrumentation-child_process 37.83% <100.00%> (-0.08%) ⬇️
instrumentations-instrumentation-cookie-parser 34.20% <0.00%> (-0.10%) ⬇️
instrumentations-instrumentation-express 34.51% <0.00%> (-0.10%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.33% <0.00%> (-0.10%) ⬇️
instrumentations-instrumentation-express-session 40.06% <100.00%> (-0.08%) ⬇️
instrumentations-instrumentation-fs 31.85% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-generic-pool 29.44% <ø> (ø)
instrumentations-instrumentation-http 39.70% <100.00%> (-0.08%) ⬇️
instrumentations-instrumentation-knex 32.24% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-mongoose 33.36% <0.00%> (-0.18%) ⬇️
instrumentations-instrumentation-multer 40.17% <100.00%> (-0.08%) ⬇️
instrumentations-instrumentation-mysql2 38.19% <100.00%> (-0.08%) ⬇️
instrumentations-instrumentation-passport 43.95% <100.00%> (-0.07%) ⬇️
instrumentations-instrumentation-passport-http 43.62% <100.00%> (-0.07%) ⬇️
instrumentations-instrumentation-passport-local 44.15% <100.00%> (-0.07%) ⬇️
instrumentations-instrumentation-pg 37.63% <100.00%> (-0.08%) ⬇️
instrumentations-instrumentation-promise 32.16% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-promise-js 32.17% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-q 32.21% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-url 32.14% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-when 32.18% <0.00%> (-0.11%) ⬇️
llmobs-ai 42.15% <100.00%> (-0.08%) ⬇️
llmobs-anthropic 40.20% <100.00%> (-0.08%) ⬇️
llmobs-bedrock 39.14% <100.00%> (-0.07%) ⬇️
llmobs-google-genai 39.68% <100.00%> (-0.07%) ⬇️
llmobs-langchain 40.03% <100.00%> (+0.04%) ⬆️
llmobs-openai 43.86% <100.00%> (-0.07%) ⬇️
llmobs-vertex-ai 39.93% <100.00%> (-0.08%) ⬇️
platform-core 31.47% <ø> (ø)
platform-esbuild 34.42% <ø> (ø)
platform-instrumentations-misc 48.41% <ø> (ø)
platform-shimmer 37.56% <ø> (ø)
platform-unit-guardrails 32.89% <ø> (ø)
plugins-azure-durable-functions 25.74% <ø> (ø)
plugins-azure-event-hubs 25.90% <ø> (ø)
plugins-azure-service-bus 25.26% <ø> (ø)
plugins-bullmq 44.17% <100.00%> (+0.05%) ⬆️
plugins-cassandra 37.68% <100.00%> (-0.21%) ⬇️
plugins-cookie 26.96% <ø> (ø)
plugins-cookie-parser 26.75% <ø> (ø)
plugins-crypto 26.73% <ø> (ø)
plugins-dd-trace-api 38.18% <0.00%> (-0.11%) ⬇️
plugins-express-mongo-sanitize 26.89% <ø> (ø)
plugins-express-session 26.70% <ø> (ø)
plugins-fastify 42.14% <100.00%> (-0.08%) ⬇️
plugins-fetch 38.26% <100.00%> (-0.08%) ⬇️
plugins-fs 38.54% <100.00%> (-0.08%) ⬇️
plugins-generic-pool 25.94% <ø> (ø)
plugins-google-cloud-pubsub 45.28% <100.00%> (-0.07%) ⬇️
plugins-grpc 40.81% <100.00%> (-0.08%) ⬇️
plugins-handlebars 26.94% <ø> (ø)
plugins-hapi 40.05% <100.00%> (-0.08%) ⬇️
plugins-hono 40.31% <100.00%> (-0.08%) ⬇️
plugins-ioredis 38.35% <100.00%> (-0.08%) ⬇️
plugins-knex 26.57% <ø> (ø)
plugins-langgraph 38.37% <100.00%> (-0.08%) ⬇️
plugins-ldapjs 24.43% <ø> (ø)
plugins-light-my-request 26.30% <ø> (ø)
plugins-limitd-client 32.51% <0.00%> (-0.11%) ⬇️
plugins-lodash 26.03% <ø> (ø)
plugins-mariadb 39.39% <100.00%> (-0.08%) ⬇️
plugins-memcached 38.06% <100.00%> (-0.08%) ⬇️
plugins-microgateway-core 39.13% <100.00%> (-0.08%) ⬇️
plugins-moleculer 40.42% <100.00%> (-0.08%) ⬇️
plugins-mongodb 39.07% <100.00%> (-0.08%) ⬇️
plugins-mongodb-core 38.90% <100.00%> (-0.08%) ⬇️
plugins-mongoose 38.78% <100.00%> (-0.08%) ⬇️
plugins-multer 26.70% <ø> (ø)
plugins-mysql 39.09% <100.00%> (-0.08%) ⬇️
plugins-mysql2 39.19% <100.00%> (-0.08%) ⬇️
plugins-node-serialize 27.00% <ø> (ø)
plugins-opensearch 37.51% <100.00%> (-0.08%) ⬇️
plugins-passport-http 26.76% <ø> (ø)
plugins-postgres 35.49% <100.00%> (-0.07%) ⬇️
plugins-process 26.73% <ø> (ø)
plugins-pug 26.96% <ø> (ø)
plugins-redis 38.76% <100.00%> (-0.08%) ⬇️
plugins-router 42.99% <100.00%> (+0.06%) ⬆️
plugins-sequelize 25.55% <ø> (ø)
plugins-test-and-upstream-amqp10 38.40% <100.00%> (-0.08%) ⬇️
plugins-test-and-upstream-amqplib 43.77% <100.00%> (-0.08%) ⬇️
plugins-test-and-upstream-apollo 39.04% <100.00%> (-0.07%) ⬇️
plugins-test-and-upstream-avsc 38.48% <0.00%> (-0.11%) ⬇️
plugins-test-and-upstream-bunyan 33.76% <0.00%> (-0.11%) ⬇️
plugins-test-and-upstream-connect 40.71% <100.00%> (-0.08%) ⬇️
plugins-test-and-upstream-graphql 39.99% <100.00%> (-0.08%) ⬇️
plugins-test-and-upstream-koa 40.30% <100.00%> (-0.08%) ⬇️
plugins-test-and-upstream-protobufjs 38.70% <0.00%> (-0.11%) ⬇️
plugins-test-and-upstream-rhea 43.92% <100.00%> (-0.11%) ⬇️
plugins-undici 39.03% <100.00%> (-0.08%) ⬇️
plugins-url 26.73% <ø> (ø)
plugins-valkey 38.02% <100.00%> (-0.08%) ⬇️
plugins-vm 26.73% <ø> (ø)
plugins-winston 33.95% <0.00%> (-0.11%) ⬇️
plugins-ws 41.79% <100.00%> (-0.08%) ⬇️
profiling-macos 40.41% <0.00%> (-0.11%) ⬇️
profiling-ubuntu 40.54% <0.00%> (-0.11%) ⬇️
profiling-windows 42.13% <0.00%> (+0.31%) ⬆️
serverless-azure-functions-client 25.62% <ø> (ø)
serverless-azure-functions-eventhubs 25.62% <ø> (ø)
serverless-azure-functions-servicebus 25.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

Overall package size

Self size: 5.04 MB
Deduped: 5.89 MB
No deduping: 5.89 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-datadog-prod-us1
Copy link
Copy Markdown

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

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 74.33% (+0.00%)

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

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 24, 2026

Benchmarks

Benchmark execution time: 2026-03-24 22:19:03

Comparing candidate commit ec8b672 in PR branch brian.marks/fix-ksr-scientific-notation with baseline commit b90857d in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 226 metrics, 34 unstable metrics.

@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 bm1549 requested review from ida613 and removed request for a team March 24, 2026 01:43
Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is good to be defensive. I think we could just make this simpler and or faster :)

*/
function formatKnuthRate (rate) {
return Number(rate.toPrecision(6)).toString()
return (Math.round(rate * 1e6) / 1e6).toFixed(6).replace(/\.?0+$/, '')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to manually round? toFixed should already do that, if I am not mistaken :)
I am also uncertain if rate is guaranteed to be a number or not. Leaning on the safe side, I guess calling Number() first is good (the type here is likely ignored in many cases).

Suggested change
return (Math.round(rate * 1e6) / 1e6).toFixed(6).replace(/\.?0+$/, '')
return Number(rate).toFixed(6).replace(/\.?0+$/, '')

We could also prevent the relative expensive replace call by checking the trailing zeroes as micro-optimization.

Suggested change
return (Math.round(rate * 1e6) / 1e6).toFixed(6).replace(/\.?0+$/, '')
const string = Number(rate).toFixed(6)
for (let i = string.length - 1; i > 0; i--) {
if (string[i] !== '0') {
return string.slice(0, i + 1)
}
}

… 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]>
* Formats a sampling rate as a string with up to 6 significant digits and no trailing zeros.
* Formats a sampling rate as a string with up to 6 decimal digits and no trailing zeros.
* Pre-rounds to 6 decimal places before calling toFixed to work around V8's imprecise
* rounding for sub-precision values (e.g. 0.0000005.toFixed(6) returns '0.000000').
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, just -0.5:

I do not think we have to worry about that. I would rather have the less precise version that is faster, since this is an edge case that should never happen in the first place and even if it would, it is still fine to handle this as an acceptable rounding result in my opinion.

function formatKnuthRate (rate) {
return Number(rate.toPrecision(6)).toString()
const string = (Math.round(Number(rate) * 1e6) / 1e6).toFixed(6)
const dot = string.indexOf('.')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just adding overhead and has no behavioral benefit. Using toFixed will always add a dot and that will be detected in the loop as not being zero. Thus, the loop will do the same amount of work and having the indexOf in addition is just adding CPU cycles.

The loop will also always find something that is not zero, so the return at the end is also not needed.

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]>
BridgeAR
BridgeAR previously approved these changes Mar 24, 2026
- 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]>
@bm1549 bm1549 force-pushed the brian.marks/fix-ksr-scientific-notation branch from 2dfedef to ec8b672 Compare March 24, 2026 22:04
@bm1549 bm1549 enabled auto-merge (squash) March 25, 2026 14:12
gh-worker-dd-mergequeue-cf854d bot pushed a commit to DataDog/dd-trace-py that referenced this pull request Mar 25, 2026
…tific notation (#17086)

## Description

Fix `_dd.p.ksr` span tag formatting for very small sampling rates. Previously, rates below 0.001 were formatted using Python's `:.6g` format which outputs scientific notation (e.g. `0.000001` → `"1e-06"`). This changes to explicit integer-level rounding and `:.6f` formatting to always produce decimal notation with up to 6 decimal digits, trailing zeros stripped.

**Related PRs:**
- dd-trace-rb: DataDog/dd-trace-rb#5497
- dd-trace-js: DataDog/dd-trace-js#7846
- system-tests: DataDog/system-tests#6466

Fixes APMAPI-1869

## Testing

- Added parametrized unit tests in `tests/tracer/test_sampler.py::test_ksr_formatting` covering:
  - Rate 1.0 → `"1"` (trailing zeros stripped)
  - Rate 0.000001 → `"0.000001"` (6 decimal precision boundary)
  - Rate 0.0000001 → `"0"` (below precision, rounds to zero)
  - Rate 0.0000005 → `"0.000001"` (rounds up to one millionth)
  - Rate 0.5 → `"0.5"` (simple case)
  - Rate 0.7654321 → `"0.765432"` (truncation at 6 decimal places)
- These match the system test cases in DataDog/system-tests#6466

## Risks

None — the formatting change only affects `_dd.p.ksr` string values for very small rates. Values ≥ 0.001 produce identical output to the previous `:.6g` format.

## Additional Notes

Uses `math.floor(rate * 1e6 + 0.5) / 1e6` instead of `round(rate * 1e6) / 1e6` to avoid Python's banker's rounding which would round `0.0000005` down to `0` instead of up to `0.000001`.

Co-authored-by: brian.marks <[email protected]>
@bm1549 bm1549 requested a review from BridgeAR March 25, 2026 17:25
@bm1549 bm1549 merged commit f657b07 into master Mar 25, 2026
1059 of 1061 checks passed
@bm1549 bm1549 deleted the brian.marks/fix-ksr-scientific-notation branch March 25, 2026 17:49
dd-octo-sts bot pushed a commit that referenced this pull request Mar 26, 2026
…tific 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]>
@dd-octo-sts dd-octo-sts bot mentioned this pull request Mar 26, 2026
tlhunter pushed a commit that referenced this pull request Mar 26, 2026
…tific 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]>
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 semver-patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants