Skip to content

[API] Preserve parent SpanContext in NoopTracer spans - #4717

Merged
marcalff merged 3 commits into
open-telemetry:mainfrom
Syedowais312:fix/noop-tracer-parent-context
Oct 20, 2026
Merged

marcalff merged 3 commits into
open-telemetry:mainfrom
Syedowais312:fix/noop-tracer-parent-context

Conversation

@Syedowais312

Copy link
Copy Markdown
Contributor

Fixes #4711

Follow-up to #4710: preserve a valid parent SpanContext when NoopTracer::StartSpan creates a non-recording span.

Changes

  • Preserve valid parent context for explicit and active-span parents.
  • Add tests for parent propagation and root or invalid contexts.
  • Update CHANGELOG.md.
  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@Syedowais312
Syedowais312 requested a review from a team as a code owner October 19, 2026 13:41
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.82%. Comparing base (cdd17eb) to head (88bda2b).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4717      +/-   ##
==========================================
+ Coverage   86.81%   86.82%   +0.01%     
==========================================
  Files         525      525              
  Lines       20736    20750      +14     
==========================================
+ Hits        18000    18014      +14     
  Misses       2736     2736              
Files with missing lines Coverage Δ
api/include/opentelemetry/trace/noop.h 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

{
return noop_span_;
}
return nostd::shared_ptr<Span>{std::make_shared<DefaultSpan>(parent_context)};

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.

This allocates inside noexcept, so an allocation failure could crash the application. But this is a wider API issue already tracked in #3013, so I won’t block this PR on it.

const StartSpanOptions &options) noexcept override
{
return noop_span_;
const auto parent_context = [&options]() noexcept -> SpanContext {

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.

This changes the inline API behavior: a no-op span now keeps the parent context instead of returning an invalid one. I’m okay with accepting this as a correctness-fix exception for v1.

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.

I agree as well.

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

LGTM once the IWYU failures are fixed.

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

LGTM, thanks for the fix.

@marcalff
marcalff merged commit bcacfec into open-telemetry:main Oct 20, 2026
75 checks passed
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.

Tracer::StartSpan does not return a span with the parent context when disabled

3 participants