#[non_exhaustive]pub struct HistogramBuilder<'a, T> {
pub instrument_provider: &'a dyn InstrumentProvider,
pub name: Cow<'static, str>,
pub description: Option<Cow<'static, str>>,
pub unit: Option<Cow<'static, str>>,
pub boundaries: Option<Vec<f64>>,
/* private fields */
}
Expand description
Configuration for building a Histogram.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.instrument_provider: &'a dyn InstrumentProvider
Instrument provider is used to create the instrument.
name: Cow<'static, str>
Name of the Histogram.
description: Option<Cow<'static, str>>
Description of the Histogram.
unit: Option<Cow<'static, str>>
Unit of the Histogram.
boundaries: Option<Vec<f64>>
Bucket boundaries for the histogram.
Implementations§
source§impl<'a, T> HistogramBuilder<'a, T>
impl<'a, T> HistogramBuilder<'a, T>
sourcepub fn with_description<S: Into<Cow<'static, str>>>(
self,
description: S,
) -> Self
pub fn with_description<S: Into<Cow<'static, str>>>( self, description: S, ) -> Self
Set the description for this instrument
sourcepub fn with_unit<S: Into<Cow<'static, str>>>(self, unit: S) -> Self
pub fn with_unit<S: Into<Cow<'static, str>>>(self, unit: S) -> Self
Set the unit for this instrument.
Unit is case sensitive(kb
is not the same as kB
).
Unit must be:
- ASCII string
- No longer than 63 characters
sourcepub fn with_boundaries(self, boundaries: Vec<f64>) -> Self
pub fn with_boundaries(self, boundaries: Vec<f64>) -> Self
Set the boundaries for this histogram.
Setting boundaries is optional. By default, the boundaries are set to:
[0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0]
§Notes
- Boundaries must not contain
f64::NAN
,f64::INFINITY
orf64::NEG_INFINITY
- Values must be in strictly increasing order (e.g., each value must be greater than the previous).
- Boundaries must not contain duplicate values.
If invalid boundaries are provided, the instrument will not report
measurements.
Providing an empty vec![]
means no bucket information will be
calculated.
§Warning
Using more buckets can improve the accuracy of percentile calculations in backends. However, this comes at a cost, including increased memory, CPU, and network usage. Choose the number of buckets carefully, considering your application’s performance and resource requirements.