Skip to content

Conversation

@genesor
Copy link
Member

@genesor genesor commented Dec 9, 2025

What does this PR do?

This PR fixes the current faulty behavior of the tracer that do not respect the parent sampling decision when the parent span is not a DataDog span but an OTel one.

Motivation

Old ER ticket APMS-15887

takes over #3718

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 ./scripts/lint.sh locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@pr-commenter
Copy link

pr-commenter bot commented Dec 9, 2025

Benchmarks

Benchmark execution time: 2025-12-09 16:00:59

Comparing candidate commit 71af6bc in PR branch ben.db/otel-sampling-decision with baseline commit 92578a2 in branch main.

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

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.21%. Comparing base (bf3079c) to head (71af6bc).
⚠️ Report is 80 commits behind head on main.

Files with missing lines Patch % Lines
ddtrace/tracer/spancontext.go 0.00% 11 Missing ⚠️
ddtrace/opentelemetry/tracer.go 70.00% 3 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
ddtrace/opentelemetry/tracer.go 91.20% <70.00%> (-2.62%) ⬇️
ddtrace/tracer/spancontext.go 88.20% <0.00%> (-1.85%) ⬇️

... and 74 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 December 10, 2025 11:45
@genesor genesor requested a review from a team as a code owner December 10, 2025 11:45
@genesor genesor requested a review from darccio December 10, 2025 12:52
Copy link
Member

@darccio darccio left a comment

Choose a reason for hiding this comment

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

LGTM


childSpanContext := span.SpanContext()
assert.Equal(t, parentSpanContext.TraceID(), childSpanContext.TraceID())
assert.True(t, childSpanContext.IsSampled(), "parent span is sampled, but child span is not sampled") // this test fails
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume you want to delete the comment on this line 😄


childSpanContext := span.SpanContext()
assert.Equal(t, parentSpanContext.TraceID(), childSpanContext.TraceID())
assert.True(t, childSpanContext.IsSampled(), "parent span is sampled, but child span is not sampled") // this test fails
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be nice to have additional tests that assert the values of IsSampled have alignment with the values returned by new methods SamplingDecision() and Priority()

if c.oc.IsSampled() {
return 2 // decisionKeep
}
return 1 // decisionDrop
Copy link
Contributor

Choose a reason for hiding this comment

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

https://pkg.go.dev/go.opentelemetry.io/otel/trace#TraceFlags.IsSampled

IsSampled reports whether the sampling bit is set in the TraceFlags.

The logic is fuzzy on this one. I would interpret this to mean: if c.oc.IsSampled() is false, then "we don't know anything about the sampling decision," instead of "the sampling decision is to drop."

p := float64(ext.PriorityAutoKeep)
return &p
}
p := float64(ext.PriorityAutoReject)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants