1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use std::result;
use std::sync::PoisonError;
use thiserror::Error;
mod async_instrument;
mod config;
mod counter;
mod descriptor;
mod kind;
mod meter;
pub mod noop;
mod number;
mod observer;
pub mod registry;
pub mod sdk_api;
mod sync_instrument;
mod up_down_counter;
mod value_recorder;
use crate::sdk::export::ExportError;
pub use async_instrument::{AsyncRunner, BatchObserverResult, Observation, ObserverResult};
pub use config::InstrumentConfig;
pub use counter::{BoundCounter, Counter, CounterBuilder};
pub use descriptor::Descriptor;
pub use kind::InstrumentKind;
pub use meter::{Meter, MeterProvider};
pub use number::{AtomicNumber, Number, NumberKind};
pub use observer::{
BatchObserver, SumObserver, SumObserverBuilder, UpDownSumObserver, UpDownSumObserverBuilder,
ValueObserver, ValueObserverBuilder,
};
pub use sync_instrument::Measurement;
pub use up_down_counter::{BoundUpDownCounter, UpDownCounter, UpDownCounterBuilder};
pub use value_recorder::{BoundValueRecorder, ValueRecorder, ValueRecorderBuilder};
pub type Result<T> = result::Result<T, MetricsError>;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum MetricsError {
#[error("Metrics error: {0}")]
Other(String),
#[error("The requested quantile is out of range")]
InvalidQuantile,
#[error("NaN value is an invalid input")]
NaNInput,
#[error("Negative value is out of range for this instrument")]
NegativeInput,
#[error("Inconsistent aggregator types: {0}")]
InconsistentAggregator(String),
#[error("No data collected by this aggregator")]
NoDataCollected,
#[error("A metric was already registered by this name with another kind or number type: {0}")]
MetricKindMismatch(String),
#[error("Inconsistent processor state")]
InconsistentState,
#[error("Aggregator does not subtract")]
NoSubtraction,
#[error("Metrics exporter {} failed with {0}", .0.exporter_name())]
ExportErr(Box<dyn ExportError>),
}
impl<T: ExportError> From<T> for MetricsError {
fn from(err: T) -> Self {
MetricsError::ExportErr(Box::new(err))
}
}
impl<T> From<PoisonError<T>> for MetricsError {
fn from(err: PoisonError<T>) -> Self {
MetricsError::Other(err.to_string())
}
}