Skip to content

fix(ddtrace/tracer): pre-compute _dd.p.dm numeric value at write-time#4576

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 10 commits into
mainfrom
dario.castane/langplat-59/no-parseint-on-dm
Mar 25, 2026
Merged

fix(ddtrace/tracer): pre-compute _dd.p.dm numeric value at write-time#4576
gh-worker-dd-mergequeue-cf854d[bot] merged 10 commits into
mainfrom
dario.castane/langplat-59/no-parseint-on-dm

Conversation

@darccio

@darccio darccio commented Mar 20, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Moves the strconv.ParseInt call for _dd.p.dm (decision maker) out of the v1 payload flush path and into the write path.

A dm uint32 field is added to the trace struct. It is kept in sync with propagatingTags[keyDecisionMaker] at all mutation sites (setPropagatingTagLocked, unsetPropagatingTagLocked, replacePropagatingTags). A shared unsetPropagatingTagLocked helper is introduced so the delete-and-clear logic is not duplicated between unsetPropagatingTag and setSamplingPriorityLockedWithForce.

payloadV1.push now reads the pre-computed value via trace.decisionMaker() instead of fetching the string from the propagating tags map and parsing it on every flush.

Motivation

payloadV1.push is called once per finished trace chunk. On every call it was acquiring a read lock, doing a map lookup, and then running strconv.ParseInt — all to read a value that was set at most once or twice during the lifetime of the trace. Moving the parse to write-time eliminates the per-flush map lookup and parse, replacing them with a single scalar read behind an RLock.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • New code is free of linting errors. You can check this by running make lint locally.
  • New code doesn't break existing tests. You can check this by running make test locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • All generated files are up to date. You can check this by running make generate locally.

@codecov

codecov Bot commented Mar 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.63%. Comparing base (0472a95) to head (1be56bb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
ddtrace/tracer/payload_v1.go 68.55% <100.00%> (ø)
ddtrace/tracer/propagating_tags.go 78.57% <100.00%> (ø)
ddtrace/tracer/spancontext.go 92.65% <100.00%> (ø)

... and 437 files with indirect coverage changes

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

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Mar 20, 2026

Copy link
Copy Markdown

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 59.90% (+0.09%)

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

@pr-commenter

pr-commenter Bot commented Mar 24, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-03-25 09:38:05

Comparing candidate commit 1be56bb in PR branch dario.castane/langplat-59/no-parseint-on-dm with baseline commit 0472a95 in branch main.

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

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@darccio
darccio marked this pull request as ready for review March 24, 2026 08:26
@darccio
darccio requested review from a team as code owners March 24, 2026 08:26

@kakkoyun kakkoyun left a comment

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.

LGTM

Comment thread ddtrace/tracer/propagating_tags.go Outdated
Comment thread ddtrace/tracer/propagating_tags.go
@darccio

darccio commented Mar 24, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6898ef772

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

log.Error("failed to convert decision maker to uint32: %s", err.Error())
}
}
sm = span.context.trace.decisionMaker()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve _dd.p.dm when encoding chunks from generic contexts

payloadV1.push now reads only trace.decisionMaker(), but the cache is not initialized on every path that sets propagating tags. In particular, FromGenericCtx assigns sc.trace.propagatingTags = ctx.PropagatingTags() directly (without calling setPropagatingTagLocked/replacePropagatingTags), so traces built from generic contexts that carry _dd.p.dm will emit samplingMechanism=0 instead of the propagated value. Before this commit, push parsed _dd.p.dm from the tags map at flush time, so this is a behavior regression for that integration path.

Useful? React with 👍 / 👎.

darccio added 2 commits March 24, 2026 18:26
…com:Datadog/dd-trace-go into dario.castane/langplat-59/no-parseint-on-dm
@darccio
darccio force-pushed the dario.castane/langplat-59/no-parseint-on-dm branch from 2a2cae7 to 1be56bb Compare March 25, 2026 09:08
@darccio

darccio commented Mar 25, 2026

Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Mar 25, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-03-25 09:09:19 UTC ℹ️ Start processing command /merge


2026-03-25 09:09:26 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals. View in MergeQueue UI.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2026-03-25 09:41:10 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 29m (p90).


2026-03-25 09:54:45 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit ef7877e into main Mar 25, 2026
209 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dario.castane/langplat-59/no-parseint-on-dm branch March 25, 2026 09:54
mtoffl01 pushed a commit that referenced this pull request Mar 25, 2026
…me (#4576)

### What does this PR do?

Moves the `strconv.ParseInt` call for `_dd.p.dm` (decision maker) out of the v1 payload flush path and into the write path.

A `dm uint32` field is added to the `trace` struct. It is kept in sync with `propagatingTags[keyDecisionMaker]` at all mutation sites (`setPropagatingTagLocked`, `unsetPropagatingTagLocked`, `replacePropagatingTags`). A shared `unsetPropagatingTagLocked` helper is introduced so the delete-and-clear logic is not duplicated between `unsetPropagatingTag` and `setSamplingPriorityLockedWithForce`.

`payloadV1.push` now reads the pre-computed value via `trace.decisionMaker()` instead of fetching the string from the propagating tags map and parsing it on every flush.

### Motivation

`payloadV1.push` is called once per finished trace chunk. On every call it was acquiring a read lock, doing a map lookup, and then running `strconv.ParseInt` — all to read a value that was set at most once or twice during the lifetime of the trace. Moving the parse to write-time eliminates the per-flush map lookup and parse, replacing them with a single scalar read behind an `RLock`.

### Reviewer's Checklist

- [x] Changed code has unit tests for its functionality at or near 100% coverage.
- [x] New code is free of linting errors. You can check this by running `make lint` locally.
- [x] New code doesn't break existing tests. You can check this by running `make test` locally.
- [x] Add an appropriate team label so this PR gets put in the right place for the release notes.
- [x] All generated files are up to date. You can check this by running `make generate` locally.


Co-authored-by: dario.castane <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants