Function f64_histogram

Source
pub fn f64_histogram(
    name: impl Into<Cow<'static, str>>,
) -> HistogramBuilder<'static, Histogram<f64>>
Expand description

Wrapper for Meter::f64_histogram using logfire’s global meter.

§Examples

We recommend using this as a static variable, like so:

use std::sync::LazyLock;
use opentelemetry::metrics::AsyncInstrument;

static HISTOGRAM: LazyLock<opentelemetry::metrics::Histogram<f64>> = LazyLock::new(|| {
    logfire::f64_histogram("my_counter")
        .with_description("Just an example")
        .with_unit("s")
        .build()
});

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // ensure logfire is configured before accessing the metric for the first time
    let shutdown_handler = logfire::configure()
        .finish()?;

    // send a value to the metric
    HISTOGRAM.record(1.0, &[]);

    shutdown_handler.shutdown()?;
    Ok(())
}