Skip to main content

init_meter_provider

Function init_meter_provider 

Source
pub fn init_meter_provider(
    resource: &Resource,
    metrics_interval_secs: u64,
) -> Result<SdkMeterProvider>
Expand description

Initialize a meter provider for OpenTelemetry metrics.

§Arguments

  • resource - The OpenTelemetry resource to use.
  • metrics_interval_secs - The interval in seconds between metric collections.

§Errors

Returns an error if the metric exporter cannot be built. When no OTLP endpoint is configured, or the endpoint env var is empty, the provider is still initialized without a periodic exporter.

§Examples

use otel_init::{get_resource, init_meter_provider};
use opentelemetry::KeyValue;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let resource = get_resource("my-service", &[]);
    let meter_provider = init_meter_provider(&resource, 30)?;
    Ok(())
}