diff --git a/opentelemetry/src/core.rs b/opentelemetry/src/core.rs index c13ff4f1f3..557c68d83c 100644 --- a/opentelemetry/src/core.rs +++ b/opentelemetry/src/core.rs @@ -260,26 +260,3 @@ impl KeyValue { } } } - -/// Units denote underlying data units tracked by `Meter`s. -#[derive(Clone, Default, Debug, PartialEq, Hash)] -pub struct Unit(String); - -impl Unit { - /// Create a new `Unit` from an `Into` - pub fn new>(value: S) -> Self { - Unit(value.into()) - } - - /// View unit as &str - pub fn as_str(&self) -> &str { - &self.0 - } -} - -impl AsRef for Unit { - #[inline] - fn as_ref(&self) -> &str { - self.0.as_ref() - } -} diff --git a/opentelemetry/src/lib.rs b/opentelemetry/src/lib.rs index 9771776512..00b091c47e 100644 --- a/opentelemetry/src/lib.rs +++ b/opentelemetry/src/lib.rs @@ -232,7 +232,7 @@ pub use context::{Context, ContextGuard}; mod core; -pub use crate::core::{Array, Key, KeyValue, Unit, Value}; +pub use crate::core::{Array, Key, KeyValue, Value}; pub mod runtime; diff --git a/opentelemetry/src/metrics/config.rs b/opentelemetry/src/metrics/config.rs index 23172deaa2..e2a6caec5d 100644 --- a/opentelemetry/src/metrics/config.rs +++ b/opentelemetry/src/metrics/config.rs @@ -1,5 +1,5 @@ +use crate::metrics::Unit; use crate::sdk::InstrumentationLibrary; -use crate::Unit; /// Config contains some options for metrics of any kind. #[derive(Clone, Debug, PartialEq, Hash)] diff --git a/opentelemetry/src/metrics/counter.rs b/opentelemetry/src/metrics/counter.rs index d45054ca3c..18c9a19fe9 100644 --- a/opentelemetry/src/metrics/counter.rs +++ b/opentelemetry/src/metrics/counter.rs @@ -1,9 +1,9 @@ use crate::{ metrics::{ sync_instrument::{SyncBoundInstrument, SyncInstrument}, - Descriptor, InstrumentKind, Measurement, Meter, Number, NumberKind, Result, + Descriptor, InstrumentKind, Measurement, Meter, Number, NumberKind, Result, Unit, }, - KeyValue, Unit, + KeyValue, }; use std::marker; diff --git a/opentelemetry/src/metrics/mod.rs b/opentelemetry/src/metrics/mod.rs index d7ffc1c2c6..fe3c4d859e 100644 --- a/opentelemetry/src/metrics/mod.rs +++ b/opentelemetry/src/metrics/mod.rs @@ -1,5 +1,6 @@ //! # OpenTelemetry Metrics API +use std::borrow::Cow; use std::result; use std::sync::PoisonError; use thiserror::Error; @@ -85,3 +86,29 @@ impl From> for MetricsError { MetricsError::Other(err.to_string()) } } + +/// Units denote underlying data units tracked by `Meter`s. +#[derive(Clone, Default, Debug, PartialEq, Hash)] +pub struct Unit(Cow<'static, str>); + +impl Unit { + /// Create a new `Unit` from an `Into` + pub fn new(value: S) -> Self + where + S: Into>, + { + Unit(value.into()) + } + + /// View unit as &str + pub fn as_str(&self) -> &str { + self.0.as_ref() + } +} + +impl AsRef for Unit { + #[inline] + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} diff --git a/opentelemetry/src/metrics/observer.rs b/opentelemetry/src/metrics/observer.rs index a0b341b16e..f46d21b4ea 100644 --- a/opentelemetry/src/metrics/observer.rs +++ b/opentelemetry/src/metrics/observer.rs @@ -1,8 +1,7 @@ use crate::metrics::{ sdk_api, AsyncRunner, Descriptor, InstrumentKind, Meter, Number, NumberKind, Observation, - Result, + Result, Unit, }; -use crate::Unit; use std::sync::Arc; /// An Observer callback that can report observations for multiple instruments. diff --git a/opentelemetry/src/metrics/up_down_counter.rs b/opentelemetry/src/metrics/up_down_counter.rs index a5a1d7d87d..a0dfc6e1c0 100644 --- a/opentelemetry/src/metrics/up_down_counter.rs +++ b/opentelemetry/src/metrics/up_down_counter.rs @@ -1,9 +1,9 @@ use crate::{ metrics::{ sync_instrument::{SyncBoundInstrument, SyncInstrument}, - Descriptor, InstrumentKind, Measurement, Meter, Number, NumberKind, Result, + Descriptor, InstrumentKind, Measurement, Meter, Number, NumberKind, Result, Unit, }, - KeyValue, Unit, + KeyValue, }; use std::marker; diff --git a/opentelemetry/src/metrics/value_recorder.rs b/opentelemetry/src/metrics/value_recorder.rs index 85117fca85..271911c396 100644 --- a/opentelemetry/src/metrics/value_recorder.rs +++ b/opentelemetry/src/metrics/value_recorder.rs @@ -1,9 +1,8 @@ use crate::metrics::{ sync_instrument::{SyncBoundInstrument, SyncInstrument}, - Descriptor, InstrumentKind, Measurement, Meter, Number, NumberKind, Result, + Descriptor, InstrumentKind, Measurement, Meter, Number, NumberKind, Result, Unit, }; use crate::KeyValue; -use crate::Unit; use std::marker; /// ValueRecorder is a metric that records per-request non-additive values.