feat(sdk): add 32-bit platform support using portable-atomic#3345
Conversation
|
|
a7893df to
10ab34f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3345 +/- ##
=====================================
Coverage 82.2% 82.2%
=====================================
Files 128 128
Lines 24506 24510 +4
=====================================
+ Hits 20147 20151 +4
Misses 4359 4359 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
10ab34f to
a4d0c4a
Compare
|
https://github.com/open-telemetry/opentelemetry-rust/pull/2773/changes could we follow similar approach from the existing PR to do this conditionally? Or we can ask the original PR to be resurrected. |
|
#2773 (comment) If possible, could you address this! Not a blocker, if this helps unblocks other projects. We have a tracking issue for this anyway. |
Why? The portable-atomic crate:
As it uses native atomics on 64-bit platforms then it is kind of conditional already. |
We try as much as possible to avoid external dependencies by default. |
You mean this comment?
No, there's another usage in test code: opentelemetry-sdk/src/logs/logger_provider.rs (lines 306, 312, 322, 681, 705):
use std::sync::atomic::AtomicU64; // in #[cfg(test)] moduleThis is test-only code, so it won't affect 32-bit builds (tests can't run on cross-compiled targets anyway). Or should I fix that as well? Also |
Replace std::sync::atomic::{AtomicI64, AtomicU64} with portable-atomic equivalents in the metrics module. This enables compilation on 32-bit ARM platforms (armv5te, armv7) which lack native 64-bit atomics.
The portable-atomic crate uses native atomics on 64-bit platforms (zero overhead) and provides a software fallback on 32-bit platforms.
a4d0c4a to
acfb104
Compare
Ok, I made it conditional. |
There was a problem hiding this comment.
Pull request overview
This PR adds 32-bit platform compatibility for the SDK metrics internals by switching 64-bit atomic counters/gauges to portable-atomic on targets that lack native 64-bit atomic support, unblocking builds on common 32-bit ARM targets.
Changes:
- Conditionally import
AtomicI64/AtomicU64fromportable_atomicwhentarget_has_atomic != "64". - Add a target-specific dependency on
portable-atomicwith thefallbackfeature for non-64-bit-atomic platforms. - Adjust internal metrics unit tests to use boxed
dyn AtomicTrackerhelpers for consistent method dispatch.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| opentelemetry-sdk/src/metrics/internal/mod.rs | Uses portable-atomic atomics on platforms without 64-bit atomics; updates related tests. |
| opentelemetry-sdk/Cargo.toml | Adds portable-atomic dependency only for targets lacking 64-bit atomics. |
| opentelemetry-sdk/CHANGELOG.md | Documents the added 32-bit platform support for metrics atomics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add 32-bit platform support by using
portable-atomicforAtomicI64andAtomicU64in the metrics module.Motivation
32-bit ARM platforms (e.g.,
armv5te-unknown-linux-gnueabi,armv7-unknown-linux-gnueabihf) lack native 64-bit atomic operations. The current use ofstd::sync::atomic::AtomicI64andAtomicU64causes compilation failures on these targets:These platforms are common in embedded/IoT environments where lightweight OpenTelemetry collection is valuable. I need this change to unblock streamfold/rotel#304
Solution
Replace
std::sync::atomic::{AtomicI64, AtomicU64}withportable_atomic::{AtomicI64, AtomicU64}.The
portable-atomiccrate:fallbackfeature