Skip to content

feat(sdk): add 32-bit platform support using portable-atomic#3345

Merged
cijothomas merged 1 commit intoopen-telemetry:mainfrom
neeme-praks-sympower:add-32bit-support
Feb 6, 2026
Merged

feat(sdk): add 32-bit platform support using portable-atomic#3345
cijothomas merged 1 commit intoopen-telemetry:mainfrom
neeme-praks-sympower:add-32bit-support

Conversation

@neeme-praks-sympower
Copy link
Contributor

Add 32-bit platform support by using portable-atomic for AtomicI64 and AtomicU64 in 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 of std::sync::atomic::AtomicI64 and AtomicU64 causes compilation failures on these targets:

error[E0432]: unresolved imports `std::sync::atomic::AtomicI64`, `std::sync::atomic::AtomicU64`

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} with portable_atomic::{AtomicI64, AtomicU64}.

The portable-atomic crate:

  • Uses native atomics on 64-bit platforms (zero overhead)
  • Provides software-based fallback on 32-bit platforms via the fallback feature
  • Is widely used and well-maintained

@neeme-praks-sympower neeme-praks-sympower requested a review from a team as a code owner February 6, 2026 08:43
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 6, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: neeme-praks-sympower / name: Neeme Praks (acfb104)

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.2%. Comparing base (8cfa981) to head (acfb104).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

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

@cijothomas
Copy link
Member

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.

@cijothomas
Copy link
Member

#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.

@neeme-praks-sympower
Copy link
Contributor Author

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.

Why?

The portable-atomic crate:

  • Uses native atomics on 64-bit platforms (zero overhead)
  • Provides software-based fallback on 32-bit platforms via the fallback feature

As it uses native atomics on 64-bit platforms then it is kind of conditional already.

@cijothomas
Copy link
Member

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.

Why?

The portable-atomic crate:

  • Uses native atomics on 64-bit platforms (zero overhead)
  • Provides software-based fallback on 32-bit platforms via the fallback feature

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.

@neeme-praks-sympower
Copy link
Contributor Author

#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.

You mean this comment?

Can you check if this is only place where Atomics were used? It's okay to do it in a follow up, if you are okay with that. (Trying to make sure we do support extra architectures consistently across repo (wherever feasible))

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)] module

This 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 docs/metrics.md has an example using AtomicU64, but that's just documentation.

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.
@neeme-praks-sympower
Copy link
Contributor Author

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.

Ok, I made it conditional.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/AtomicU64 from portable_atomic when target_has_atomic != "64".
  • Add a target-specific dependency on portable-atomic with the fallback feature for non-64-bit-atomic platforms.
  • Adjust internal metrics unit tests to use boxed dyn AtomicTracker helpers 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.

@cijothomas cijothomas merged commit 0948c61 into open-telemetry:main Feb 6, 2026
33 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.

3 participants