Skip to main content

init_metrics_provider

Function init_metrics_provider 

Source
pub fn init_metrics_provider(otel_cfg: &OpenTelemetryConfig) -> Result<()>
Expand description

Build a [SdkMeterProvider] from the resolved metrics exporter settings and register it as the global meter provider.

When metrics.enabled is false the function is a no-op: the global meter provider stays as the built-in [NoopMeterProvider] (zero overhead — all instruments obtained via global::meter_with_scope() become no-op).

Exporter resolution: opentelemetry.metrics.exporter overrides opentelemetry.exporter when present.

This function is guarded by [OnceLock] — the provider is built and registered at most once; subsequent calls return the cached result.

§Errors

The OTLP metric exporter cannot be constructed.