Skip to content

Commit

Permalink
Move unit into metrics module (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtescher committed Jun 6, 2021
1 parent 99e51c1 commit 635f10e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
23 changes: 0 additions & 23 deletions opentelemetry/src/core.rs
Expand Up @@ -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<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
27 changes: 27 additions & 0 deletions 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;
Expand Down Expand Up @@ -85,3 +86,29 @@ impl<T> From<PoisonError<T>> 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<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()
}
}
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
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

0 comments on commit 635f10e

Please sign in to comment.