Skip to content

fix(ddtrace/tracer): wire version on aggregation key when adding a span to client-side stats#4734

Merged
darccio merged 1 commit into
release-v2.8.xfrom
dario.castane/er/synthetics-issue-v2.8.x
May 7, 2026
Merged

fix(ddtrace/tracer): wire version on aggregation key when adding a span to client-side stats#4734
darccio merged 1 commit into
release-v2.8.xfrom
dario.castane/er/synthetics-issue-v2.8.x

Conversation

@darccio

@darccio darccio commented May 6, 2026

Copy link
Copy Markdown
Member

What does this PR do?

ddtrace/tracer/stats.go — 3 changes

1. tracerStatSpan gets a version field

type tracerStatSpan struct {
    statSpan *stats.StatSpan
    origin   string
    version  string  // per-span version tag; "" means use global aggKey version
}

The struct that carries a finished span to the concentrator's goroutine now also carries whatever version meta tag was on the span.

2. newTracerStatSpan captures ext.Version from the span meta

return &tracerStatSpan{
    statSpan: statSpan,
    origin:   s.meta[keyOrigin],
    version:  s.meta[ext.Version],  // ← new
}, true

Called on the hot path when a span finishes. Reads s.meta["version"] — the same tag synthtracer sets via tracer.Tag("version", currentVersion()).

3. add() overrides the payload aggregation key version per-span

func (c *concentrator) add(s *tracerStatSpan) {
    aggKey := c.aggregationKey          // value copy — c.aggregationKey unchanged
    if s.version != "" {
        aggKey.Version = s.version      // per-span version wins
    }
    c.spanConcentrator.AddSpan(s.statSpan, aggKey, "", nil, s.origin)
}

c.aggregationKey is built once at startup with Version = c.internalConfig.Version() (empty for synthtracer). Before this fix, every span used that frozen empty version → N/A. Now each span can carry its own version into a separate stats bucket, matching what the agent-side concentrator does when computing server-side stats.


ddtrace/tracer/stats_test.goTestPerSpanVersionInStats

Three sub-tests that pin the behaviour:

Sub-test What it verifies
per-span version propagates to stats payload Span with version tag → ClientStatsPayload.Version matches tag (was failing before fix)
falls back to global config version when span has no version tag No span tag → uses WithServiceVersion() / DD_VERSION (existing behaviour preserved)
two spans with different versions produce separate payloads Different per-span versions → separate stats payloads, not collapsed under "" (was failing before fix)

Motivation

Ensure that stats are properly tagged with the version, both global and per-span.

Root cause:

  • PR feat(tracer): periodically poll agent /info endpoint for dynamic capability updates #4451 (commit 6e49f81) introduced periodic /info polling every 5s in v2.8.0.
  • DropP0s + Stats are dynamic fields refreshed by that poll.
  • Once the sidecar agent's client_drop_p0s: true is detected (after startup), the concentrator activates.
  • The concentrator's aggregationKey.Version was set at construction from c.internalConfig.Version() = "" (no global version).
  • All client-side stats are emitted with version="" → N/A.
  • The agent-side concentrator reads version from each span's meta["version"] via pt.AppVersion, so it always picked up the rotating tag. Client-side does not.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • 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.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running make fix-modules locally.

Unsure? Have a question? Request a review!

@darccio
darccio requested a review from a team as a code owner May 6, 2026 16:46
@darccio darccio 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 May 6, 2026
@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.86%. Comparing base (2b2b2c2) to head (5655505).

Additional details and impacted files
Files with missing lines Coverage Δ
ddtrace/tracer/stats.go 97.29% <100.00%> (+0.05%) ⬆️

... and 87 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-prod-us1-6

datadog-prod-us1-6 Bot commented May 6, 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: 61.21% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5655505 | Docs | Datadog PR Page | Give us feedback!

@pr-commenter

pr-commenter Bot commented May 6, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-05-06 17:33:54

Comparing candidate commit 5655505 in PR branch dario.castane/er/synthetics-issue-v2.8.x with baseline commit 2b2b2c2 in branch release-v2.8.x.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 93 metrics, 0 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 merged commit d8d1fc4 into release-v2.8.x May 7, 2026
213 of 216 checks passed
@darccio
darccio deleted the dario.castane/er/synthetics-issue-v2.8.x branch May 7, 2026 13:29
@noraibrahimi

Copy link
Copy Markdown

hi @darccio. Starting with version 2.8.2 the resource is not visible in the DD Tracer tab anymore, only the HTTP method.
Downgrading to 2.8.1 fixed the issue. Can it be related to these changes?

Screenshot 2026-06-29 at 16 15 59

@darccio

darccio commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

@noraibrahimi We'd appreicate if you open a issue for this. Regarding the changes you mention, they could be related but this is a legitimate fix for a found bug: DataDog/system-tests#6869

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