Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ tracing-log = "0.2"
tracing-opentelemetry = "0.30"
typed-builder = "0.20"
uuid = "1.3"
portable-atomic = "1.9.0"

# Aviod use of crates.io version of these crates through the tracing-opentelemetry dependencies
[patch.crates-io]
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ tokio = { workspace = true, features = ["rt", "time"], optional = true }
tokio-stream = { workspace = true, optional = true }
http = { workspace = true, optional = true }

[target.'cfg(any(target_arch = "xtensa"))'.dependencies]
portable-atomic = {workspace = true}

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
27 changes: 17 additions & 10 deletions opentelemetry-sdk/src/metrics/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ use core::fmt;
use std::collections::{HashMap, HashSet};
use std::mem::swap;
use std::ops::{Add, AddAssign, DerefMut, Sub};
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize, Ordering};
use std::sync::atomic::Ordering;

#[cfg(not(target_arch = "xtensa"))]
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize};

#[cfg(target_arch = "xtensa")]
use portable_atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize};

use std::sync::{Arc, OnceLock, RwLock};

pub(crate) use aggregate::{AggregateBuilder, AggregateFns, ComputeAggregation, Measure};
Expand Down Expand Up @@ -519,8 +526,8 @@ mod tests {
#[test]
fn can_add_and_get_u64_atomic_value() {
let atomic = u64::new_atomic_tracker(0);
atomic.add(15);
atomic.add(10);
AtomicTracker::add(&atomic, 15);
AtomicTracker::add(&atomic, 10);

let value = atomic.get_value();
assert_eq!(value, 25);
Expand All @@ -529,7 +536,7 @@ mod tests {
#[test]
fn can_reset_u64_atomic_value() {
let atomic = u64::new_atomic_tracker(0);
atomic.add(15);
AtomicTracker::add(&atomic, 15);

let value = atomic.get_and_reset_value();
let value2 = atomic.get_value();
Expand Down Expand Up @@ -558,8 +565,8 @@ mod tests {
#[test]
fn can_add_and_get_i64_atomic_value() {
let atomic = i64::new_atomic_tracker(0);
atomic.add(15);
atomic.add(-10);
AtomicTracker::add(&atomic, 15);
AtomicTracker::add(&atomic, -10);

let value = atomic.get_value();
assert_eq!(value, 5);
Expand All @@ -568,7 +575,7 @@ mod tests {
#[test]
fn can_reset_i64_atomic_value() {
let atomic = i64::new_atomic_tracker(0);
atomic.add(15);
AtomicTracker::add(&atomic, 15);

let value = atomic.get_and_reset_value();
let value2 = atomic.get_value();
Expand Down Expand Up @@ -597,8 +604,8 @@ mod tests {
#[test]
fn can_add_and_get_f64_atomic_value() {
let atomic = f64::new_atomic_tracker(0.0);
atomic.add(15.3);
atomic.add(10.4);
AtomicTracker::add(&atomic, 15.3);
AtomicTracker::add(&atomic, 10.4);

let value = atomic.get_value();

Expand All @@ -608,7 +615,7 @@ mod tests {
#[test]
fn can_reset_f64_atomic_value() {
let atomic = f64::new_atomic_tracker(0.0);
atomic.add(15.5);
AtomicTracker::add(&atomic, 15.5);

let value = atomic.get_and_reset_value();
let value2 = atomic.get_value();
Expand Down