Skip to content

fix(tracer): preserve keep/drop possibility for OTel bridge on unsampled spans#4631

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 6 commits intomainfrom
ben.db/fix-otel-bridge-unsampled-span-drop
Apr 8, 2026
Merged

fix(tracer): preserve keep/drop possibility for OTel bridge on unsampled spans#4631
gh-worker-dd-mergequeue-cf854d[bot] merged 6 commits intomainfrom
ben.db/fix-otel-bridge-unsampled-span-drop

Conversation

@genesor
Copy link
Copy Markdown
Member

@genesor genesor commented Apr 2, 2026

What does this PR do?

Fixes the OTel bridge's handling of unsampled spans in FromGenericCtx. Previously, when an OTel parent context had IsSampled() == false, the bridge set samplingDecision = decisionDrop directly on the trace. Bypassing the atomic Compare-And-Swap (CAS) semantics that keep() and drop() rely on.

This meant:

  • Error spans could never rescue the trace as keep() only CAS from decisionNone, not decisionDrop
  • The behavior diverged from the native DD tracer, where P0 traces are not hard-dropped client-side

The fix leaves samplingDecision as decisionNone for drop decisions while still setting the P0 priority and locking the trace against resampling. This preserves the OTel sampling intent while restoring the native DD keep/drop CAS flow.

The bug has been introduced in v2.6.0 following: #4238

Motivation

Fixes #4624

Discovered during investigation of APMS-19054 — a customer upgrading to dd-trace-go v2.6.0 + OTel observed trace.* metrics dropping to near-zero under low sampling rates when client-side stats were disabled.

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.

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Apr 2, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 60.12%

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.73%. Comparing base (e36675b) to head (45ff255).

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

... and 439 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.

@genesor genesor marked this pull request as ready for review April 2, 2026 15:51
@genesor genesor requested review from a team as code owners April 2, 2026 15:51
@genesor genesor changed the title fix(tracer): preserve keep/drop CAS semantics for OTel bridge unsampled spans fix(tracer): preserve keep/drop possibility for OTel bridge on unsampled spans Apr 2, 2026
Copy link
Copy Markdown
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

LGTM. Great comments!

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Apr 8, 2026

Benchmarks

Benchmark execution time: 2026-04-08 16:03:59

Comparing candidate commit 45ff255 in PR branch ben.db/fix-otel-bridge-unsampled-span-drop with baseline commit e36675b 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 ----------------------------------'

@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit 75bd185 into main Apr 8, 2026
217 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the ben.db/fix-otel-bridge-unsampled-span-drop branch April 8, 2026 16:20
genesor added a commit that referenced this pull request Apr 14, 2026
…led spans (#4631)

Fixes the OTel bridge's handling of unsampled spans in `FromGenericCtx`. Previously, when an OTel parent context had `IsSampled() == false`, the bridge set `samplingDecision = decisionDrop` directly on the trace. Bypassing the atomic Compare-And-Swap (CAS) semantics that `keep()` and `drop()` rely on.

This meant:
- Error spans could never rescue the trace as `keep()` only CAS from `decisionNone`, not `decisionDrop`
- The behavior diverged from the native DD tracer, where P0 traces are not hard-dropped client-side

The fix leaves `samplingDecision` as `decisionNone` for drop decisions while still setting the P0 priority and locking the trace against resampling. This preserves the OTel sampling intent while restoring the native DD keep/drop CAS flow.

The bug has been introduced in `v2.6.0` following: #4238

Fixes #4624

Discovered during investigation of [APMS-19054](https://datadoghq.atlassian.net/browse/APMS-19054) — a customer upgrading to dd-trace-go v2.6.0 + OTel observed `trace.*` metrics dropping to near-zero under low sampling rates when client-side stats were disabled.

- [ ] Changed code has unit tests for its functionality at or near 100% coverage.
- [ ] [System-Tests](https://github.com/DataDog/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.

[APMS-19054]: https://datadoghq.atlassian.net/browse/APMS-19054?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

Co-authored-by: kakkoyun <kakkoyun@users.noreply.github.com>
Co-authored-by: benjamin.debernardi <benjamin.debernardi@datadoghq.com>
genesor added a commit that referenced this pull request Apr 14, 2026
…led spans (#4631)

Fixes the OTel bridge's handling of unsampled spans in `FromGenericCtx`. Previously, when an OTel parent context had `IsSampled() == false`, the bridge set `samplingDecision = decisionDrop` directly on the trace. Bypassing the atomic Compare-And-Swap (CAS) semantics that `keep()` and `drop()` rely on.

This meant:
- Error spans could never rescue the trace as `keep()` only CAS from `decisionNone`, not `decisionDrop`
- The behavior diverged from the native DD tracer, where P0 traces are not hard-dropped client-side

The fix leaves `samplingDecision` as `decisionNone` for drop decisions while still setting the P0 priority and locking the trace against resampling. This preserves the OTel sampling intent while restoring the native DD keep/drop CAS flow.

The bug has been introduced in `v2.6.0` following: #4238

Fixes #4624

Discovered during investigation of [APMS-19054](https://datadoghq.atlassian.net/browse/APMS-19054) — a customer upgrading to dd-trace-go v2.6.0 + OTel observed `trace.*` metrics dropping to near-zero under low sampling rates when client-side stats were disabled.

- [ ] Changed code has unit tests for its functionality at or near 100% coverage.
- [ ] [System-Tests](https://github.com/DataDog/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.

[APMS-19054]: https://datadoghq.atlassian.net/browse/APMS-19054?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

Co-authored-by: kakkoyun <kakkoyun@users.noreply.github.com>
Co-authored-by: benjamin.debernardi <benjamin.debernardi@datadoghq.com>
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.

[BUG]: Unsampled OTel spans are always dropped client-side

4 participants