Skip to content

[API] Never set a null global provider or propagator - #4420

Merged
marcalff merged 9 commits into
open-telemetry:mainfrom
denizariyan:bugfix/never-set-null-provider
Aug 13, 2026
Merged

marcalff merged 9 commits into
open-telemetry:mainfrom
denizariyan:bugfix/never-set-null-provider

Conversation

@denizariyan

@denizariyan denizariyan commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #3694 and a bit more

Changes

  • Installs the corresponding noop provider/propagator when given a null to prevent unintended nullptr de-ref via getters that promise to never return a null.
  • While this does change the observable behaviour of stable public API, given it is the expected behaviour as documented already and is a correctness fix I believe it fits in the carve out in the ABI policy to be delivered without ABI level guard.
  • This explicitly calls new in a noexcept function which could lead to program termination on bad alloc etc. This is left for the overall cleanup as part of Code flagged noexcept should not raise exceptions #4361
  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@denizariyan denizariyan changed the title [WIP] [API] Never set null provider [WIP] [API] Never set a null global provider or propagator Aug 12, 2026
@denizariyan
denizariyan force-pushed the bugfix/never-set-null-provider branch from 318a7bd to b2eb8b0 Compare August 12, 2026 19:15
@denizariyan
denizariyan force-pushed the bugfix/never-set-null-provider branch from b2eb8b0 to 984dbc7 Compare August 12, 2026 19:16
@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.59%. Comparing base (089779d) to head (c0ed2c7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4420      +/-   ##
==========================================
+ Coverage   82.58%   82.59%   +0.02%     
==========================================
  Files         511      511              
  Lines       20018    20039      +21     
==========================================
+ Hits        16529    16550      +21     
  Misses       3489     3489              
Files with missing lines Coverage Δ
...ntelemetry/context/propagation/global_propagator.h 100.00% <100.00%> (ø)
api/include/opentelemetry/logs/provider.h 100.00% <100.00%> (ø)
api/include/opentelemetry/metrics/provider.h 100.00% <100.00%> (ø)
api/include/opentelemetry/trace/provider.h 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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

Copy link
Copy Markdown
Member

Please see CI failures:

Warning: include-what-you-use reported diagnostics:

/home/runner/work/opentelemetry-cpp/opentelemetry-cpp/api/test/context/propagation/global_propagator_test.cc should add these lines:
#include <utility>                                                  // for pair

@denizariyan
denizariyan marked this pull request as ready for review August 13, 2026 04:20
@denizariyan
denizariyan requested a review from a team as a code owner August 13, 2026 04:20
@denizariyan denizariyan changed the title [WIP] [API] Never set a null global provider or propagator [API] Never set a null global provider or propagator Aug 13, 2026

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

Thanks for the fix!

Comment thread CHANGELOG.md
during cleanup no longer risks a nullptr de-ref on a later use.
**Note**: this is a correctness fix to an inline API header; the observable
behavior of these methods changes towards the already documented contract
(see `docs/abi-policy.md`).

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.

The API change does impact observable behavior within the stable ABIv1, but considering this a correctness fix seems reasonable.

@marcalff
marcalff merged commit cb17c27 into open-telemetry:main Aug 13, 2026
73 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.

Avoid setting an empty (null) TraceProvider in trace::Provider::SetTracerProvider

3 participants