Skip to content

fix(ddtrace/opentelemetry): propagate sampling decision to child spans #3673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

darccio
Copy link
Member

@darccio darccio commented Jun 20, 2025

What does this PR do?

Propagates the parent context's sampling decision to child spans if parent has been sampled.

Motivation

Closes #3639.

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 golangci-lint run 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 Jun 20, 2025

Benchmarks

Benchmark execution time: 2025-06-20 07:54:21

Comparing candidate commit 2e84c0b in PR branch dario.castane/langplat-603/sampling-decision-fix with baseline commit 2bcfa37 in branch main.

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

@darccio darccio marked this pull request as draft June 20, 2025 15:28
@darccio
Copy link
Member Author

darccio commented Jun 20, 2025

Converting to draft as @mtoffl01 pointed off-line some good reasons about this PR duplicating logic deep in the chain.

@@ -44,6 +44,9 @@ func (t *oteltracer) Start(ctx context.Context, spanName string, opts ...oteltra
// if the span doesn't originate from the Datadog tracer,
// use SpanContextW3C implementation struct to pass span context information
ddopts = append(ddopts, tracer.ChildOf(tracer.FromGenericCtx(&otelCtxToDDCtx{sctx})))
if sctx.IsSampled() {
ddopts = append(ddopts, tracer.Tag(ext.ManualKeep, true))
Copy link

Choose a reason for hiding this comment

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

This doesn't look right.

If the parent span is sampled, the new span shouldn't need to get force-sampled to get sampled. This will incorrectly set the ingestion_reason span metadata to manual instead of rule (relevant doc).

Also, this doesn't cover the case when the parent span is not sampled. In that case, the child span shouldn't be sampled either. However, with this code, the child span will independently decide its sampling decision, so it might be sampled.

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.

[BUG]: Sampling decision in OpenTelemetry span context is ignored
3 participants