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.

Initialisation runs at most once on success and is cached. Errors are not cached — a transient failure (e.g. OTLP endpoint briefly unreachable) is returned to the caller, and a subsequent call may retry.

§Errors

The OTLP metric exporter cannot be constructed.