Skip to content

Fix _dd.p.ksr formatting to use 6 significant digits without trailing zeros#288

Draft
bm1549 wants to merge 3 commits intomainfrom
brian.marks/fix-ksr-formatting
Draft

Fix _dd.p.ksr formatting to use 6 significant digits without trailing zeros#288
bm1549 wants to merge 3 commits intomainfrom
brian.marks/fix-ksr-formatting

Conversation

@bm1549
Copy link
Contributor

@bm1549 bm1549 commented Mar 11, 2026

Description

Fixes _dd.p.ksr value formatting from std::to_string() (which produces trailing zeros like "1.000000") to snprintf("%.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.ksr but used std::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 %.6g format specifier used by all other tracers.

See RFC: "Transmit Knuth sampling rate to backend"

Additional Notes

Key files changed:

  • src/datadog/trace_segment.cpp — Added format_rate() helper using snprintf("%.6g")
  • test/test_trace_segment.cpp — Updated 3 assertions
  • test/test_span.cpp — Updated 6 W3C tracestate expectations

Related PRs across tracers:

Jira ticket: APMSP-1867

🤖 Generated with Claude Code

… 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>
@pr-commenter
Copy link

pr-commenter bot commented Mar 11, 2026

Benchmarks

Benchmark execution time: 2026-03-11 02:52:05

Comparing candidate commit ef4d91b in PR branch brian.marks/fix-ksr-formatting with baseline commit f8c3913 in branch main.

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>
@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 11, 2026
@datadog-datadog-prod-us1
Copy link

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

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 87.78% (+0.01%)

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

@codecov-commenter
Copy link

codecov-commenter commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.78%. Comparing base (f8c3913) to head (ef4d91b).

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants