Skip to content

Commit

Permalink
fix: enable exponential histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Apr 16, 2024
1 parent 52e40c6 commit 1ef219b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
29 changes: 29 additions & 0 deletions crates/metrics/src/custom_aggregation_selector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use opentelemetry_sdk::metrics::{
reader::{AggregationSelector, DefaultAggregationSelector},
Aggregation, InstrumentKind,
};

#[derive(Clone, Default, Debug)]
pub struct CustomAggregationSelector {
default_aggregation_selector: DefaultAggregationSelector,
}

impl CustomAggregationSelector {
/// Create a new default aggregation selector.
pub fn new() -> Self {
Self::default()
}
}

impl AggregationSelector for CustomAggregationSelector {
fn aggregation(&self, kind: InstrumentKind) -> Aggregation {
match kind {
InstrumentKind::Histogram => Aggregation::Base2ExponentialHistogram {
max_size: 160,
max_scale: 20,
record_min_max: true,
},
x => self.default_aggregation_selector.aggregation(x),
}
}
}
5 changes: 4 additions & 1 deletion crates/metrics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use {future::*, once_cell::sync::Lazy, opentelemetry as otel, task::*};
use {
custom_aggregation_selector::CustomAggregationSelector,
opentelemetry_sdk::metrics::SdkMeterProvider,
otel::metrics::{Meter, MeterProvider},
prometheus::{Error as PrometheusError, Registry, TextEncoder},
Expand All @@ -8,7 +8,9 @@ use {
time::Duration,
},
};
pub use {future::*, once_cell::sync::Lazy, opentelemetry as otel, task::*};

pub mod custom_aggregation_selector;
pub mod future;
pub mod macros;
pub mod task;
Expand All @@ -22,6 +24,7 @@ static METRICS_CORE: Lazy<Arc<ServiceMetrics>> = Lazy::new(|| {

let registry = Registry::new();
let prometheus_exporter = opentelemetry_prometheus::exporter()
.with_aggregation_selector(CustomAggregationSelector::new())
.with_registry(registry.clone())
.build()
.unwrap();
Expand Down

0 comments on commit 1ef219b

Please sign in to comment.