Add _dd.p.ksr propagated tag for Knuth sampling rate#3701
Add _dd.p.ksr propagated tag for Knuth sampling rate#3701
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
✨ Fix all issues with BitsAI or with Cursor
|
The default sampling mechanism (DD_MECHANISM_DEFAULT) is not an agent rate. Per the RFC, _dd.p.ksr should only be set for "Agent Sampling rate or Trace Sampling rules". This prevents _dd.p.ksr from appearing on every span when no agent rates are configured. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3701 +/- ##
==========================================
- Coverage 62.40% 62.30% -0.11%
==========================================
Files 142 142
Lines 13586 13586
Branches 1775 1775
==========================================
- Hits 8479 8465 -14
- Misses 4301 4314 +13
- Partials 806 807 +1 see 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
The inferred proxy sampling rules test uses explicit DD_TRACE_SAMPLING_RULES which triggers rule-based sampling. The ksr tag now appears in span meta. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Two fixes for remaining CI failures after the initial KSR tag implementation: 1. serializer.c: Copy _dd.p.ksr from the root span to the inferred proxy span during serialization (using false to keep it on the root span too), matching the behavior expected by sampling_rules.phpt. 2. SpanChecker.php: Auto-ignore _dd.p.ksr in withExactTags() assertions unless the test explicitly tests for it, consistent with how _dd.p.dm and _dd.p.tid are handled. This fixes ResponseStatusCodeTest and other integration tests that don't test KSR behavior directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Benchmarks [ tracer ]Benchmark execution time: 2026-03-11 05:33:12 Comparing candidate commit db13664 in PR branch Found 0 performance improvements and 23 performance regressions! Performance is the same for 170 metrics, 1 unstable metrics. scenario:ContextPropagationBench/benchInject64Bit
scenario:ContextPropagationBench/benchInject64Bit-opcache
scenario:MessagePackSerializationBench/benchMessagePackSerialization-opcache
scenario:SamplingRuleMatchingBench/benchGlobMatching1
scenario:SamplingRuleMatchingBench/benchGlobMatching1-opcache
scenario:SamplingRuleMatchingBench/benchGlobMatching2
scenario:SamplingRuleMatchingBench/benchGlobMatching2-opcache
scenario:SamplingRuleMatchingBench/benchGlobMatching3
scenario:SamplingRuleMatchingBench/benchGlobMatching3-opcache
scenario:SamplingRuleMatchingBench/benchGlobMatching4
scenario:SamplingRuleMatchingBench/benchGlobMatching4-opcache
scenario:SamplingRuleMatchingBench/benchRegexMatching1
scenario:SamplingRuleMatchingBench/benchRegexMatching1-opcache
scenario:SamplingRuleMatchingBench/benchRegexMatching2
scenario:SamplingRuleMatchingBench/benchRegexMatching2-opcache
scenario:SamplingRuleMatchingBench/benchRegexMatching3
scenario:SamplingRuleMatchingBench/benchRegexMatching3-opcache
scenario:SamplingRuleMatchingBench/benchRegexMatching4
scenario:SamplingRuleMatchingBench/benchRegexMatching4-opcache
scenario:SpanBench/benchOpenTelemetryAPI
scenario:SpanBench/benchOpenTelemetryAPI-opcache
scenario:SpanBench/benchOpenTelemetryInteroperability
scenario:SpanBench/benchOpenTelemetryInteroperability-opcache
|
In the hot sampling path, avoid re-allocating strings and updating hash tables when _dd.p.ksr already contains the same value. This optimization recovers most of the performance regression seen in SamplingRuleMatchingBench when sampling is re-evaluated with the same rate (the common case for long-running spans). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| zend_hash_str_del(metrics, ZEND_STRL("_dd.rule_psr")); | ||
| } else { | ||
| zend_hash_str_update(metrics, ZEND_STRL("_dd.rule_psr"), &sample_rate_zv); | ||
| dd_update_knuth_sampling_rate_tag(span, sample_rate); |
There was a problem hiding this comment.
Is it intentional that the _dd.p.ksr is not deleted where the psr is deleted?
| #include <json/json.h> | ||
|
|
||
| #include "../configuration.h" | ||
| #include "../tracer_tag_propagation/tracer_tag_propagation.h" |
There was a problem hiding this comment.
Redundant header inclusion.
Description
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 spanmeta(string type) with up to 6 significant digits and no trailing zeros.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"
Key files changed:
ext/priority_sampling/priority_sampling.c— Addeddd_update_knuth_sampling_rate_tag()functionRelated PRs across tracers:
Reviewer checklist
🤖 Generated with Claude Code