Skip to content

Add _dd.p.ksr propagated tag for Knuth sampling rate#7741

Draft
bm1549 wants to merge 2 commits intomasterfrom
brian.marks/add-ksr-tag
Draft

Add _dd.p.ksr propagated tag for Knuth sampling rate#7741
bm1549 wants to merge 2 commits intomasterfrom
brian.marks/add-ksr-tag

Conversation

@bm1549
Copy link
Contributor

@bm1549 bm1549 commented Mar 11, 2026

What does this PR do?

Adds _dd.p.ksr (Knuth Sampling Rate) as a propagated tag set when agent-based or rule-based sampling decisions are made. The tag is stored in span meta (string type) with up to 6 significant digits and no trailing zeros.

Motivation

To enable consistent sampling across tracers and backend retention filters, the backend needs to know the sampling rate applied by the tracer. Without transmitting the tracer's rate via _dd.p.ksr, backend resampling cannot correctly compute effective rates in multi-stage sampling scenarios.

See RFC: "Transmit Knuth sampling rate to backend"

Additional Notes

Key files changed:

  • packages/dd-trace/src/constants.js — Added SAMPLING_KNUTH_RATE constant
  • packages/dd-trace/src/priority_sampler.js — Added formatKnuthRate() and set ksr in agent/rule sampling paths
  • packages/dd-trace/test/priority_sampler.spec.js — 7 test cases

Related PRs across tracers:

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

Overall package size

Self size: 4.95 MB
Deduped: 5.79 MB
No deduping: 5.79 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

@pr-commenter
Copy link

pr-commenter bot commented Mar 11, 2026

Benchmarks

Benchmark execution time: 2026-03-11 02:53:56

Comparing candidate commit 8a10db8 in PR branch brian.marks/add-ksr-tag with baseline commit e97f095 in branch master.

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

@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.40%. Comparing base (e97f095) to head (8a10db8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7741   +/-   ##
=======================================
  Coverage   80.40%   80.40%           
=======================================
  Files         741      741           
  Lines       32084    32090    +6     
=======================================
+ Hits        25796    25802    +6     
  Misses       6288     6288           
Flag Coverage Δ
aiguard-macos 38.90% <87.50%> (-0.08%) ⬇️
aiguard-ubuntu 39.02% <87.50%> (-0.08%) ⬇️
aiguard-windows 38.75% <87.50%> (-0.08%) ⬇️
apm-capabilities-tracing-macos 48.86% <100.00%> (+<0.01%) ⬆️
apm-capabilities-tracing-ubuntu 48.95% <100.00%> (+0.01%) ⬆️
apm-capabilities-tracing-windows 48.66% <100.00%> (-0.01%) ⬇️
apm-integrations-child-process 38.46% <87.50%> (-0.08%) ⬇️
apm-integrations-couchbase-18 37.24% <87.50%> (-0.21%) ⬇️
apm-integrations-couchbase-eol 37.85% <87.50%> (-0.07%) ⬇️
apm-integrations-oracledb 37.69% <87.50%> (-0.07%) ⬇️
appsec-express 55.15% <87.50%> (-0.06%) ⬇️
appsec-fastify 51.51% <87.50%> (-0.05%) ⬇️
appsec-graphql 51.70% <87.50%> (-0.05%) ⬇️
appsec-kafka 44.23% <87.50%> (-0.06%) ⬇️
appsec-ldapjs 43.91% <75.00%> (-0.07%) ⬇️
appsec-lodash 43.54% <0.00%> (-0.10%) ⬇️
appsec-macos 58.19% <87.50%> (-0.05%) ⬇️
appsec-mongodb-core 48.70% <87.50%> (-0.06%) ⬇️
appsec-mongoose 49.37% <87.50%> (-0.06%) ⬇️
appsec-mysql 50.74% <75.00%> (-0.06%) ⬇️
appsec-node-serialize 43.09% <75.00%> (-0.07%) ⬇️
appsec-passport 47.50% <87.50%> (-0.06%) ⬇️
appsec-postgres 50.50% <75.00%> (-0.06%) ⬇️
appsec-sourcing 42.51% <87.50%> (-0.06%) ⬇️
appsec-template 43.25% <75.00%> (-0.07%) ⬇️
appsec-ubuntu 58.27% <87.50%> (-0.05%) ⬇️
appsec-windows 58.03% <87.50%> (-0.05%) ⬇️
instrumentations-instrumentation-bluebird 32.28% <0.00%> (-0.12%) ⬇️
instrumentations-instrumentation-body-parser 40.40% <87.50%> (-0.07%) ⬇️
instrumentations-instrumentation-child_process 37.78% <87.50%> (-0.08%) ⬇️
instrumentations-instrumentation-cookie-parser 34.26% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-express 34.58% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.39% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-express-session 40.03% <87.50%> (-0.07%) ⬇️
instrumentations-instrumentation-fs 31.90% <0.00%> (-0.12%) ⬇️
instrumentations-instrumentation-generic-pool 29.91% <ø> (ø)
instrumentations-instrumentation-http 39.75% <87.50%> (-0.07%) ⬇️
instrumentations-instrumentation-knex 32.29% <0.00%> (-0.12%) ⬇️
instrumentations-instrumentation-mongoose 33.41% <0.00%> (-0.11%) ⬇️
instrumentations-instrumentation-multer 40.15% <87.50%> (-0.07%) ⬇️
instrumentations-instrumentation-mysql2 38.24% <87.50%> (-0.07%) ⬇️
instrumentations-instrumentation-passport 43.89% <75.00%> (-0.08%) ⬇️
instrumentations-instrumentation-passport-http 43.57% <87.50%> (-0.07%) ⬇️
instrumentations-instrumentation-passport-local 44.11% <87.50%> (-0.07%) ⬇️
instrumentations-instrumentation-pg 37.67% <87.50%> (-0.08%) ⬇️
instrumentations-instrumentation-promise 32.21% <0.00%> (-0.12%) ⬇️
instrumentations-instrumentation-promise-js 32.22% <0.00%> (-0.12%) ⬇️
instrumentations-instrumentation-q 32.26% <0.00%> (-0.12%) ⬇️
instrumentations-instrumentation-url 32.18% <0.00%> (-0.12%) ⬇️
instrumentations-instrumentation-when 32.23% <0.00%> (-0.12%) ⬇️
llmobs-ai 42.22% <87.50%> (-0.07%) ⬇️
llmobs-anthropic 40.21% <87.50%> (-0.07%) ⬇️
llmobs-bedrock 39.19% <87.50%> (-0.06%) ⬇️
llmobs-google-genai 39.75% <87.50%> (-0.07%) ⬇️
llmobs-langchain 39.98% <87.50%> (-0.06%) ⬇️
llmobs-openai 43.93% <87.50%> (-0.07%) ⬇️
llmobs-vertex-ai 40.00% <87.50%> (-0.07%) ⬇️
platform-core 31.53% <ø> (ø)
platform-esbuild 34.48% <ø> (ø)
platform-instrumentations-misc 48.40% <ø> (ø)
platform-shimmer 37.63% <ø> (ø)
platform-unit-guardrails 32.95% <ø> (ø)
plugins-azure-event-hubs 25.83% <ø> (ø)
plugins-azure-service-bus 25.19% <ø> (ø)
plugins-bullmq 44.20% <87.50%> (-0.07%) ⬇️
plugins-cassandra 37.72% <87.50%> (-0.07%) ⬇️
plugins-cookie 26.89% <ø> (ø)
plugins-cookie-parser 26.67% <ø> (ø)
plugins-crypto 26.79% <ø> (ø)
plugins-dd-trace-api 38.26% <50.00%> (-0.11%) ⬇️
plugins-express-mongo-sanitize 26.82% <ø> (ø)
plugins-express-session 26.63% <ø> (ø)
plugins-fastify 42.11% <87.50%> (-0.07%) ⬇️
plugins-fetch 38.29% <87.50%> (-0.07%) ⬇️
plugins-fs 38.56% <87.50%> (-0.08%) ⬇️
plugins-generic-pool 25.87% <ø> (ø)
plugins-google-cloud-pubsub 45.32% <87.50%> (-0.06%) ⬇️
plugins-grpc 40.84% <87.50%> (-0.07%) ⬇️
plugins-handlebars 26.86% <ø> (ø)
plugins-hapi 40.03% <87.50%> (-0.07%) ⬇️
plugins-hono 40.29% <87.50%> (-0.07%) ⬇️
plugins-ioredis 38.37% <87.50%> (-0.08%) ⬇️
plugins-knex 26.50% <ø> (ø)
plugins-ldapjs 24.36% <ø> (ø)
plugins-light-my-request 26.23% <ø> (ø)
plugins-limitd-client 32.56% <0.00%> (-0.12%) ⬇️
plugins-lodash 25.96% <ø> (ø)
plugins-mariadb 39.42% <87.50%> (-0.08%) ⬇️
plugins-memcached 38.10% <87.50%> (-0.08%) ⬇️
plugins-microgateway-core 39.09% <87.50%> (-0.15%) ⬇️
plugins-moleculer 40.44% <87.50%> (-0.06%) ⬇️
plugins-mongodb 39.12% <100.00%> (-0.06%) ⬇️
plugins-mongodb-core 38.96% <100.00%> (-0.07%) ⬇️
plugins-mongoose 38.80% <87.50%> (-0.07%) ⬇️
plugins-multer 26.63% <ø> (ø)
plugins-mysql 39.12% <100.00%> (-0.07%) ⬇️
plugins-mysql2 39.22% <100.00%> (-0.07%) ⬇️
plugins-node-serialize 26.93% <ø> (ø)
plugins-opensearch 37.56% <87.50%> (-0.07%) ⬇️
plugins-passport-http 26.68% <ø> (ø)
plugins-postgres 35.69% <100.00%> (-0.06%) ⬇️
plugins-process 26.79% <ø> (ø)
plugins-pug 26.89% <ø> (ø)
plugins-redis 38.69% <87.50%> (-0.08%) ⬇️
plugins-router 42.84% <87.50%> (-0.06%) ⬇️
plugins-sequelize 25.47% <ø> (ø)
plugins-test-and-upstream-amqp10 38.45% <87.50%> (-0.08%) ⬇️
plugins-test-and-upstream-amqplib 43.79% <87.50%> (-0.07%) ⬇️
plugins-test-and-upstream-apollo 38.95% <87.50%> (-0.07%) ⬇️
plugins-test-and-upstream-avsc 38.59% <50.00%> (-0.11%) ⬇️
plugins-test-and-upstream-bunyan 33.82% <0.00%> (-0.12%) ⬇️
plugins-test-and-upstream-connect 40.68% <87.50%> (-0.07%) ⬇️
plugins-test-and-upstream-graphql 40.06% <87.50%> (-0.07%) ⬇️
plugins-test-and-upstream-koa 40.27% <87.50%> (-0.07%) ⬇️
plugins-test-and-upstream-protobufjs 38.82% <50.00%> (-0.11%) ⬇️
plugins-test-and-upstream-rhea 43.95% <87.50%> (-0.07%) ⬇️
plugins-undici 39.06% <87.50%> (-0.04%) ⬇️
plugins-url 26.79% <ø> (ø)
plugins-valkey 38.04% <87.50%> (-0.08%) ⬇️
plugins-vm 26.79% <ø> (ø)
plugins-winston 34.01% <0.00%> (-0.12%) ⬇️
plugins-ws 41.79% <87.50%> (-0.07%) ⬇️
profiling-macos 39.84% <50.00%> (-0.10%) ⬇️
profiling-ubuntu 39.97% <50.00%> (-0.10%) ⬇️
profiling-windows 41.15% <50.00%> (-0.10%) ⬇️
serverless-azure-functions-client 25.54% <ø> (ø)
serverless-azure-functions-eventhubs 25.54% <ø> (ø)
serverless-azure-functions-servicebus 25.54% <ø> (ø)

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.

Only set the SAMPLING_KNUTH_RATE (_dd.p.ksr) tag when actual agent
rates have been received (SAMPLING_MECHANISM_AGENT), not when using
the built-in default sampler (SAMPLING_MECHANISM_DEFAULT).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant