Repository navigation
[API] Never set a null global provider or propagator #4420
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
Merged
marcalff
merged 9 commits into
open-telemetry:main
from
denizariyan:bugfix/never-set-null-provider
Aug 13, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
83f49c0
[API] Never set a null global TextMapPropagator
denizariyan 1572d45
[API] Never set a null global LoggerProvider or EventLoggerProvider
denizariyan 25d7958
[API] Never set a null global MeterProvider
denizariyan 52e96dc
[API] Never set a null global TracerProvider
denizariyan da0816c
[TEST] Expect no-op globals after ConfiguredSdk::UnInstall
denizariyan 984dbc7
[DOC] Add changelog entry for the null global provider fix
denizariyan 17e0266
[TEST] Add missing include in global_propagator_test
denizariyan b24446f
Merge branch 'main' into bugfix/never-set-null-provider
denizariyan c0ed2c7
Merge branch 'main' into bugfix/never-set-null-provider
marcalff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include <cstdint> | ||
| #include <map> | ||
| #include <string> | ||
| #include <utility> | ||
|
|
||
| #include "opentelemetry/context/context.h" | ||
| #include "opentelemetry/context/propagation/global_propagator.h" | ||
| #include "opentelemetry/context/propagation/text_map_propagator.h" | ||
| #include "opentelemetry/nostd/function_ref.h" | ||
| #include "opentelemetry/nostd/shared_ptr.h" | ||
| #include "opentelemetry/nostd/string_view.h" | ||
| #include "opentelemetry/nostd/variant.h" | ||
|
|
||
| using opentelemetry::context::propagation::GlobalTextMapPropagator; | ||
| using opentelemetry::context::propagation::TextMapCarrier; | ||
| using opentelemetry::context::propagation::TextMapPropagator; | ||
|
|
||
| namespace context = opentelemetry::context; | ||
| namespace nostd = opentelemetry::nostd; | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| class TextMapCarrierTest : public TextMapCarrier | ||
| { | ||
| public: | ||
| nostd::string_view Get(nostd::string_view key) const noexcept override | ||
| { | ||
| auto it = headers_.find(std::string(key)); | ||
| if (it != headers_.end()) | ||
| { | ||
| return nostd::string_view(it->second); | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| void Set(nostd::string_view key, nostd::string_view value) noexcept override | ||
| { | ||
| headers_[std::string(key)] = std::string(value); | ||
| } | ||
|
|
||
| std::map<std::string, std::string> headers_; | ||
| }; | ||
|
|
||
| class TestPropagator : public TextMapPropagator | ||
| { | ||
| public: | ||
| context::Context Extract(const TextMapCarrier & /* carrier */, | ||
| context::Context &context) noexcept override | ||
| { | ||
| return context; | ||
| } | ||
|
|
||
| void Inject(TextMapCarrier &carrier, const context::Context & /* context */) noexcept override | ||
| { | ||
| carrier.Set("test", "value"); | ||
| } | ||
|
|
||
| bool Fields(nostd::function_ref<bool(nostd::string_view)> /* callback */) const noexcept override | ||
| { | ||
| return true; | ||
| } | ||
| }; | ||
|
|
||
| TEST(GlobalPropagator, GetGlobalPropagatorDefault) | ||
| { | ||
| auto propagator = GlobalTextMapPropagator::GetGlobalPropagator(); | ||
| EXPECT_NE(nullptr, propagator); | ||
| } | ||
|
|
||
| TEST(GlobalPropagator, SetGlobalPropagator) | ||
| { | ||
| auto propagator = nostd::shared_ptr<TextMapPropagator>(new TestPropagator()); | ||
| GlobalTextMapPropagator::SetGlobalPropagator(propagator); | ||
| ASSERT_EQ(propagator, GlobalTextMapPropagator::GetGlobalPropagator()); | ||
| } | ||
|
|
||
| TEST(GlobalPropagator, SetNullGlobalPropagator) | ||
| { | ||
| auto propagator = nostd::shared_ptr<TextMapPropagator>(new TestPropagator()); | ||
| GlobalTextMapPropagator::SetGlobalPropagator(propagator); | ||
| ASSERT_EQ(propagator, GlobalTextMapPropagator::GetGlobalPropagator()); | ||
|
|
||
| // Setting a null TextMapPropagator installs a no-op TextMapPropagator. | ||
| GlobalTextMapPropagator::SetGlobalPropagator(nostd::shared_ptr<TextMapPropagator>()); | ||
|
|
||
| auto noop = GlobalTextMapPropagator::GetGlobalPropagator(); | ||
| ASSERT_NE(nullptr, noop); | ||
| ASSERT_NE(propagator, noop); | ||
|
|
||
| // The no-op TextMapPropagator is usable, it does not crash on use. | ||
| TextMapCarrierTest carrier; | ||
| context::Context context = context::Context{"key", static_cast<int64_t>(42)}; | ||
|
|
||
| // The no-op inject writes nothing to the carrier. | ||
| noop->Inject(carrier, context); | ||
| EXPECT_TRUE(carrier.headers_.empty()); | ||
|
|
||
| // The no-op extract returns the input context. | ||
| context::Context extracted = noop->Extract(carrier, context); | ||
| EXPECT_EQ(42, nostd::get<int64_t>(extracted.GetValue("key"))); | ||
| } | ||
|
|
||
| } // namespace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.