-
Notifications
You must be signed in to change notification settings - Fork 599
Replace once_cell::Lazy with std::sync::OnceLock for global Initialization in OpenTelemetry API crate
#2326
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
Replace once_cell::Lazy with std::sync::OnceLock for global Initialization in OpenTelemetry API crate
#2326
Conversation
once_cell::Lazy with std::sync::OnceLock for global Initialization in OpenTelemetry API crate
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2326 +/- ##
=======================================
- Coverage 79.5% 79.4% -0.1%
=======================================
Files 123 123
Lines 21258 21271 +13
=======================================
+ Hits 16905 16910 +5
- Misses 4353 4361 +8 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
cijothomas
left a comment
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.
Thanks for driving to keep external dependencies minimal!
Lets merge after we get one more eyes to review.
| Lazy::new(NoopTextMapPropagator::new); | ||
| static DEFAULT_TEXT_MAP_PROPAGATOR: OnceLock<NoopTextMapPropagator> = OnceLock::new(); | ||
|
|
||
| /// Ensures the `GLOBAL_TEXT_MAP_PROPAGATOR` is initialized with a `NoopTextMapPropagator`. |
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.
nit: For each of these methods, we could use a comment similar to what we have for Baggage:
/// Returns the default baggage, ensuring it is initialized only once.
So, something like:
/// Returns the global TextMapPropagator ensuring it is initialized only once.
We have |
utpilla
left a comment
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.
Left some non-blocking suggestions.
Yes we can discuss this separate to this PR, as it will affect the trace consumers relying on the default build. |
For 1.0, it'd better to remove trace from default features, as we are not in a position to declare traces as stable. Lets track this separately. |
Changes
std::sync::OnceLockwas stabilized in Rust 1.70.0, providing equivalent functionality toonce_cell::Lazydirectly in the standard library. This change reduces the dependency on an external crate (once_cell) for a feature now natively supported.once_cell::Lazyandstd::sync::OnceLockguarantee thread-safe, one-time initialization of global variables. The replacement does not alter the functionality or behavior of the code.pin-project-lite,futures-sink,futures-core,thiserrorare made optional dependencies, and only used whentracefeature is enabled. With this,opentelemetrycrate doesn't use any external crate for logs and metrics.Example of change for TracerProvider:
Before:
After
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial, user-facing changes