Skip to content

Commit

Permalink
[Metrics API] Remove unnecessary auto trait implementations (open-tel…
Browse files Browse the repository at this point in the history
…emetry#2215)

Co-authored-by: Cijo Thomas <[email protected]>
  • Loading branch information
utpilla and cijothomas authored Oct 16, 2024
1 parent 20f1204 commit e6965bd
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 36 deletions.
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn calculate_hash(values: &[KeyValue]) -> u64 {

impl AttributeSet {
fn new(mut values: Vec<KeyValue>) -> Self {
values.sort_unstable();
values.sort_unstable_by(|a, b| a.key.cmp(&b.key));
let hash = calculate_hash(&values);
AttributeSet(values, hash)
}
Expand Down
1 change: 1 addition & 0 deletions opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions opentelemetry/src/metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! # OpenTelemetry Metrics API

use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
use std::result;
use std::sync::Arc;
Expand Down Expand Up @@ -91,19 +90,6 @@ impl Hash for KeyValue {
}
}

impl PartialOrd for KeyValue {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
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
Expand Down Expand Up @@ -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<T: Hash>(item: &T) -> u64 {
let mut hasher = DefaultHasher::new();
item.hash(&mut hasher);
Expand Down

0 comments on commit e6965bd

Please sign in to comment.