Skip to content

Commit

Permalink
[Metrics API] Mark KeyValue types non-exhaustive (#2228)
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla authored Oct 23, 2024
1 parent a47b429 commit f45e840
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions opentelemetry-proto/src/transform/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ pub mod tonic {
Array::I64(vals) => array_into_proto(vals),
Array::F64(vals) => array_into_proto(vals),
Array::String(vals) => array_into_proto(vals),
_ => unreachable!("Nonexistent array type"), // Needs to be updated when new array types are added
})),
_ => unreachable!("Nonexistent value type"), // Needs to be updated when new value types are added
},
}
}
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-stdout/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ impl From<opentelemetry::Value> for Value {
opentelemetry::Array::String(s) => {
Value::Array(s.into_iter().map(|s| Value::String(s.into())).collect())
}
_ => unreachable!("Nonexistent array type"), // Needs to be updated when new array types are added
},
_ => unreachable!("Nonexistent value type"), // Needs to be updated when new value types are added
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
- 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)
- - **Breaking change for log exporter authors:** Marked `AnyValue` enum as `non_exhaustive`. [#2230](https://github.com/open-telemetry/opentelemetry-rust/pull/2230)
- **Breaking change for exporter authors:** Marked `KeyValue` related structs and enums as `non_exhaustive`. [#2228](https://github.com/open-telemetry/opentelemetry-rust/pull/2228)
- **Breaking change for log exporter authors:** Marked `AnyValue` enum as `non_exhaustive`. [#2230](https://github.com/open-telemetry/opentelemetry-rust/pull/2230)

## v0.26.0
Released 2024-Sep-30
Expand Down
5 changes: 5 additions & 0 deletions opentelemetry/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{fmt, hash};
/// See the [attribute naming] spec for guidelines.
///
/// [attribute naming]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/attribute-naming.md
#[non_exhaustive]
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Key(OtelString);

Expand Down Expand Up @@ -149,6 +150,7 @@ impl hash::Hash for OtelString {
}

/// A [Value::Array] containing homogeneous values.
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq)]
pub enum Array {
/// Array of bools
Expand Down Expand Up @@ -212,6 +214,7 @@ into_array!(
);

/// The value part of attribute [KeyValue] pairs.
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq)]
pub enum Value {
/// bool values
Expand All @@ -227,6 +230,7 @@ pub enum Value {
}

/// Wrapper for string-like values
#[non_exhaustive]
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct StringValue(OtelString);

Expand Down Expand Up @@ -372,6 +376,7 @@ impl fmt::Display for Value {

/// A key-value pair describing an attribute.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct KeyValue {
/// The attribute name
pub key: Key,
Expand Down

0 comments on commit f45e840

Please sign in to comment.