pub fn metrics_provider(
endpoint: Option<String>,
resource_detectors: Vec<Box<dyn ResourceDetector>>,
histogram_buckets: Vec<HistogramBuckets>,
) -> Result<SdkMeterProvider>Expand description
Builds an SdkMeterProvider configured to export to an OTLP collector.
Aside from endpoint, it pulls OTEL configuration from the environment based on the
variables defined here and
here.
endpoint overrides the collector endpoint the environment would otherwise select (via
OTEL_EXPORTER_OTLP_ENDPOINT/OTEL_EXPORTER_OTLP_METRICS_ENDPOINT), for callers that take
their own explicit configuration (e.g. a CLI flag) rather than expecting operators to set
OTel’s environment variables directly. Pass None to use the environment as normal.
resource_detectors lets the caller contribute additional resource attributes.
They run before this crate’s own detectors, which set fields from OTEL_RESOURCE_ATTRIBUTES
and telemetry.sdk{name, language, version}.
The caller is responsible for registering the returned provider as the global one (e.g. via
opentelemetry::global::set_meter_provider). Instruments created by the macros in this
module (e.g. counter) bind to whatever meter
provider is global at the time they’re first used, and never rebind afterwards.
Exposed publicly so embedders that manage their own tracing::Subscriber (and so can’t call
crate::init, which also installs one) can still set up Spin’s metrics: build a provider
with this function and register it themselves, alongside their own, via
opentelemetry::global::set_meter_provider.