diff --git a/opentelemetry-sdk/src/metrics/mod.rs b/opentelemetry-sdk/src/metrics/mod.rs index e4c0de3026..681b0af8a8 100644 --- a/opentelemetry-sdk/src/metrics/mod.rs +++ b/opentelemetry-sdk/src/metrics/mod.rs @@ -104,7 +104,7 @@ fn calculate_hash(values: &[KeyValue]) -> u64 { impl AttributeSet { fn new(mut values: Vec) -> Self { - values.sort_unstable(); + values.sort_unstable_by(|a, b| a.key.cmp(&b.key)); let hash = calculate_hash(&values); AttributeSet(values, hash) } diff --git a/opentelemetry/CHANGELOG.md b/opentelemetry/CHANGELOG.md index cbe3269d3b..3f55515db4 100644 --- a/opentelemetry/CHANGELOG.md +++ b/opentelemetry/CHANGELOG.md @@ -7,6 +7,7 @@ - Removed unnecessary public methods named `as_any` from `AsyncInstrument` trait and the implementing instruments: `ObservableCounter`, `ObservableGauge`, and `ObservableUpDownCounter` [#2187](https://github.com/open-telemetry/opentelemetry-rust/pull/2187) - Introduced `SyncInstrument` trait to replace the individual synchronous instrument traits (`SyncCounter`, `SyncGauge`, `SyncHistogram`, `SyncUpDownCounter`) which are meant for SDK implementation. [#2207](https://github.com/open-telemetry/opentelemetry-rust/pull/2207) - Ensured that `observe` method on asynchronous instruments can only be called inside a callback. This was done by removing the implementation of `AsyncInstrument` trait for each of the asynchronous instruments. [#2210](https://github.com/open-telemetry/opentelemetry-rust/pull/2210) +- Removed `PartialOrd` and `Ord` implementations for `KeyValue`. [#2215](https://github.com/open-telemetry/opentelemetry-rust/pull/2215) ## v0.26.0 Released 2024-Sep-30 diff --git a/opentelemetry/src/metrics/mod.rs b/opentelemetry/src/metrics/mod.rs index 9ce27f53b6..de3022d5dc 100644 --- a/opentelemetry/src/metrics/mod.rs +++ b/opentelemetry/src/metrics/mod.rs @@ -1,6 +1,5 @@ //! # OpenTelemetry Metrics API -use std::cmp::Ordering; use std::hash::{Hash, Hasher}; use std::result; use std::sync::Arc; @@ -91,19 +90,6 @@ impl Hash for KeyValue { } } -impl PartialOrd for KeyValue { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -/// Ordering is based on the key only. -impl Ord for KeyValue { - fn cmp(&self, other: &Self) -> Ordering { - self.key.cmp(&other.key) - } -} - impl Eq for KeyValue {} /// SDK implemented trait for creating instruments @@ -300,27 +286,6 @@ mod tests { } } - #[test] - fn kv_float_order() { - // TODO: Extend this test to all value types, not just F64 - let float_vals = [ - 0.0, - 1.0, - -1.0, - f64::INFINITY, - f64::NEG_INFINITY, - f64::NAN, - f64::MIN, - f64::MAX, - ]; - - for v in float_vals { - let kv1 = KeyValue::new("a", v); - let kv2 = KeyValue::new("b", v); - assert!(kv1 < kv2, "Order is solely based on key!"); - } - } - fn hash_helper(item: &T) -> u64 { let mut hasher = DefaultHasher::new(); item.hash(&mut hasher);