Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move unit into metrics module #564

Merged
merged 2 commits into from Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 0 additions & 22 deletions opentelemetry/src/core.rs
Expand Up @@ -261,25 +261,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<String>`
pub fn new<S: Into<String>>(value: S) -> Self {
Unit(value.into())
}

/// View unit as &str
pub fn as_str(&self) -> &str {
&self.0
}
}

impl AsRef<str> for Unit {
#[inline]
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}
2 changes: 1 addition & 1 deletion opentelemetry/src/lib.rs
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion 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)]
Expand Down
4 changes: 2 additions & 2 deletions 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;

Expand Down
2 changes: 2 additions & 0 deletions opentelemetry/src/metrics/mod.rs
Expand Up @@ -16,6 +16,7 @@ mod observer;
pub mod registry;
pub mod sdk_api;
mod sync_instrument;
mod unit;
mod up_down_counter;
mod value_recorder;

Expand All @@ -32,6 +33,7 @@ pub use observer::{
ValueObserver, ValueObserverBuilder,
};
pub use sync_instrument::Measurement;
pub use unit::Unit;
pub use up_down_counter::{BoundUpDownCounter, UpDownCounter, UpDownCounterBuilder};
pub use value_recorder::{BoundValueRecorder, ValueRecorder, ValueRecorderBuilder};

Expand Down
3 changes: 1 addition & 2 deletions 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.
Expand Down
27 changes: 27 additions & 0 deletions opentelemetry/src/metrics/unit.rs
@@ -0,0 +1,27 @@
use std::borrow::Cow;

/// 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<String>`
pub fn new<S>(value: S) -> Self
where
S: Into<Cow<'static, str>>,
{
Unit(value.into())
}

/// View unit as &str
pub fn as_str(&self) -> &str {
self.0.as_ref()
}
}

impl AsRef<str> for Unit {
#[inline]
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}
4 changes: 2 additions & 2 deletions 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;

Expand Down
3 changes: 1 addition & 2 deletions 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.
Expand Down