opentelemetry/metrics/instruments/
histogram.rs1use crate::KeyValue;
2use core::fmt;
3use std::sync::Arc;
4
5use super::SyncInstrument;
6
7#[derive(Clone)]
13#[non_exhaustive]
14pub struct Histogram<T>(Arc<dyn SyncInstrument<T> + Send + Sync>);
15
16impl<T> fmt::Debug for Histogram<T>
17where
18 T: fmt::Debug,
19{
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 f.write_fmt(format_args!("Histogram<{}>", std::any::type_name::<T>()))
22 }
23}
24
25impl<T> Histogram<T> {
26 pub fn new(inner: Arc<dyn SyncInstrument<T> + Send + Sync>) -> Self {
28 Histogram(inner)
29 }
30
31 pub fn record(&self, value: T, attributes: &[KeyValue]) {
33 self.0.measure(value, attributes)
34 }
35}