Skip to content

feat(ddtrace/tracer): add tracer.StartSpanFromPropagatedContext to start a span from a propagated context#4492

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 11 commits into
mainfrom
dario.castane/poc/continue-span
Apr 14, 2026
Merged

feat(ddtrace/tracer): add tracer.StartSpanFromPropagatedContext to start a span from a propagated context#4492
gh-worker-dd-mergequeue-cf854d[bot] merged 11 commits into
mainfrom
dario.castane/poc/continue-span

Conversation

@darccio

@darccio darccio commented Mar 3, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Adds tracer.StartSpanFromPropagatedContext to start spans from propagated context.

Implements variant D from RFC: https://docs.google.com/document/d/12s7DyHu4AqoC2u_-1aFhod1BcStRAHFlDn1tFuERlMM/edit?tab=t.0. It's A+C because using generics and restricting the carriers to TextMapReader effectively implement - at compile time - functions that don't accept carriers of any type.

It also avoids coupling ddtrace/tracer more with net/http and allows custom TextMapReader implementers. It's also more flexible if we want to support more carriers.

Motivation

Resolves #3598.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • There is a benchmark for any new code, or changes to existing code.
  • 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.

Unsure? Have a question? Request a review!

@darccio
darccio requested review from a team as code owners March 3, 2026 11:49
@codecov

codecov Bot commented Mar 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.03%. Comparing base (bd8a42c) to head (05a3625).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
ddtrace/tracer/tracer.go 66.66% 2 Missing and 2 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
ddtrace/tracer/tracer.go 87.54% <66.66%> (ø)

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

@pr-commenter

pr-commenter Bot commented Mar 3, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-04-14 11:51:12

Comparing candidate commit 6a5ffed in PR branch dario.castane/poc/continue-span with baseline commit dd184a0 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 ----------------------------------'

@mtoffl01 mtoffl01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this will be a nice win for our API users 🥳

But, I don't like the name ContinueSpan 😬. I don't think it's accurate -- we're not extending or "continuing" an existing span, we're creating a new one, either as a child of the parent span, or as a root span of a new trace. What about StartSpanFromCarrier? It aligns with the StartSpanFromContext format, and these functions pretty much do the same thing, except one starts a span from a carrier, and the other from a context 😉

Comment thread ddtrace/tracer/tracer.go Outdated
@darccio
darccio requested review from genesor and mtoffl01 March 9, 2026 18:21

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

Nice work on this, Dario. The generic TextMapReader constraint is a really elegant choice — it gives us type safety at compile time while keeping things flexible for all carrier types. Much better than having to maintain separate functions per carrier.

I have a few suggestions below, mostly around error semantics and the SpanLinks pattern. Nothing blocking the direction, just things worth discussing.

Comment thread ddtrace/tracer/tracer.go
Comment thread ddtrace/tracer/tracer.go Outdated
Comment thread ddtrace/tracer/tracer.go Outdated
Comment thread ddtrace/tracer/tracer_test.go
@datadog-official

datadog-official Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 63.64%
Overall Coverage: 60.11%

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

@darccio

darccio commented Mar 11, 2026

Copy link
Copy Markdown
Member Author

Feedback applied in ad23248 and 13ef564.

@darccio darccio changed the title feat(ddtrace/tracer): add tracer.ContinueSpan to start a span from a propagated context feat(ddtrace/tracer): add tracer.StartSpanFromPropagatedContext to start a span from a propagated context Mar 11, 2026
Comment thread ddtrace/tracer/api.txt Outdated

@genesor genesor 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.

Great work!

@darccio
darccio requested a review from a team March 12, 2026 11:29
Comment thread ddtrace/tracer/tracer.go
@darccio
darccio requested review from a team and rarguelloF March 12, 2026 14:20

@rarguelloF rarguelloF left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice!! LGTM 🚀

@kakkoyun

Copy link
Copy Markdown
Member

@mtoffl01 it is waiting for you :)

@mtoffl01 mtoffl01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be a nice improvement to our user experience, thanks for doing it!!!

@RomainMuller RomainMuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That API surface looks fine to me at this stage.

It does not prohibit adding specific helpers (in the future) to cut some boilerplate out if we determine this is useful/necessary (i.e, StartSpanFromHTTPHeadersPropagatedContext or something like that).

@darccio
darccio requested a review from felixge March 17, 2026 16:13
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.

Lack of convenient API to start span with a parent context in v2

6 participants