Fix _dd.p.ksr formatting to use 6 significant digits without trailing zeros#288
Draft
Fix _dd.p.ksr formatting to use 6 significant digits without trailing zeros#288
Conversation
… zeros
Replace std::to_string() (which uses sprintf "%f" producing 6 trailing
decimal places) with snprintf "%.6g" which produces up to 6 significant
digits with no trailing zeros. This matches the behavior of Python's
f"{rate:.6g}" and Go's strconv.FormatFloat(rate, 'g', 6, 64).
Examples: 1.0 -> "1", 0.5 -> "0.5", 0.0 -> "0"
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BenchmarksBenchmark execution time: 2026-03-11 02:52:05 Comparing candidate commit ef4d91b in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. |
Reformat the emplace_back call to match clang-format's expected style (arguments on one line with alignment) to fix the verify CI job. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Mar 11, 2026
|
🎯 Code Coverage (details) 🔗 Commit SHA: ef4d91b | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #288 +/- ##
==========================================
+ Coverage 87.76% 87.78% +0.01%
==========================================
Files 84 84
Lines 5658 5663 +5
==========================================
+ Hits 4966 4971 +5
Misses 692 692 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The ksr trace tag should only be set when the sampling decision comes from an explicit source (agent rate, rule, or remote rule). When the DEFAULT mechanism is used — meaning no agent configuration has been received yet — the rate is a hardcoded 100% and ksr is meaningless. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes
_dd.p.ksrvalue formatting fromstd::to_string()(which produces trailing zeros like"1.000000") tosnprintf("%.6g")(no trailing zeros, up to 6 significant digits). This aligns C++ with all other tracer implementations.Motivation
The C++ tracer already set
_dd.p.ksrbut usedstd::to_string()for formatting, which always produces 6 decimal places (e.g.,"1.000000"instead of"1"). The RFC specifies up to 6 significant digits with no trailing zeros, matching the%.6gformat specifier used by all other tracers.See RFC: "Transmit Knuth sampling rate to backend"
Additional Notes
Key files changed:
src/datadog/trace_segment.cpp— Addedformat_rate()helper usingsnprintf("%.6g")test/test_trace_segment.cpp— Updated 3 assertionstest/test_span.cpp— Updated 6 W3C tracestate expectationsRelated PRs across tracers:
Jira ticket: APMSP-1867
🤖 Generated with Claude Code