Skip to content

[SDK] Fix disabled Tracer StartSpan noop behavior - #4710

Merged
marcalff merged 3 commits into
open-telemetry:mainfrom
dbarker:fix_disabled_tracer_noop_behavior
Oct 18, 2026
Merged

marcalff merged 3 commits into
open-telemetry:mainfrom
dbarker:fix_disabled_tracer_noop_behavior

Conversation

@dbarker

@dbarker dbarker commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Contributes to #4711

The current Tracer::StartSpan API and SDK disabled "noop behavior" is to return a non-recording span with an invalid span context, however the spec requires the noop span to contain the parent's context if valid. This is important to prevent breaking traces that propagate through libraries/processes where tracers or the entire SDK is disabled.

The spec defines the noop behavior here: https://opentelemetry.io/docs/specs/otel/trace/api/#behavior-of-the-api-in-the-absence-of-an-installed-sdk

The API MUST return a non-recording Span with the SpanContext in the parent Context (whether explicitly given or implicit current).

This PR only addresses the SDK Tracer's disabled behavior to meet the spec. A follow up PR will be required to fix the API's noop tracer to meet the spec for when the SDK is fully disabled.

Changes

  • Update SDK Tracer to return a non-recording span with the parent's span context when disabled.
  • Add test cases for all parent context propagation options when calling StartSpan
  • Add new tracer benchmark cases to cover the new behavior

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@dbarker
dbarker marked this pull request as ready for review October 17, 2026 19:14
@dbarker
dbarker requested a review from a team as a code owner October 17, 2026 19:14
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.81%. Comparing base (a273994) to head (3b3ac18).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4710      +/-   ##
==========================================
+ Coverage   86.81%   86.81%   +0.01%     
==========================================
  Files         525      525              
  Lines       20739    20741       +2     
==========================================
+ Hits        18003    18005       +2     
  Misses       2736     2736              
Files with missing lines Coverage Δ
sdk/src/trace/tracer.cc 84.15% <100.00%> (+0.40%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbarker dbarker added the pr:please-review This PR is ready for review label Oct 18, 2026

@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 2fc5227 into open-telemetry:main Oct 18, 2026
75 checks passed
@dbarker
dbarker deleted the fix_disabled_tracer_noop_behavior branch October 18, 2026 19:21
malkia added a commit to malkia/opentelemetry-cpp that referenced this pull request Oct 18, 2026
[SDK] Fix disabled Tracer StartSpan noop behavior (open-telemetry#4710)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:please-review This PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants