pub struct Registry { /* private fields */ }Expand description
A registry mapping metric names (+ optional fixed labels) to metrics.
Implementations§
Source§impl Registry
impl Registry
Sourcepub fn counter(&self, key: &str, help: &str) -> Arc<Counter>
pub fn counter(&self, key: &str, help: &str) -> Arc<Counter>
Register (or fetch) a counter. key must be a valid Prometheus series
name with optional {label="v"} suffix.
Panics if key is already registered as a histogram; a silent
overwrite would detach the existing metric from the registry and
lose every observation collected against it. Also panics if key
contains a byte that would corrupt Prometheus text exposition
(cross-line bytes anywhere; " or \\ in the base name — both
stay legal inside the label section) — this catches accidental
interpolation of
attacker-controlled strings into a metric key at registration
rather than surfacing corrupt scrape output later.
Sourcepub fn histogram(&self, key: &str, help: &str) -> Arc<Histogram>
pub fn histogram(&self, key: &str, help: &str) -> Arc<Histogram>
Register (or fetch) a histogram with default latency buckets.
Panics if key is already registered as a counter; a silent overwrite
would detach the existing metric from the registry and lose every
observation collected against it. Same key-byte guard as
Self::counter.
Sourcepub fn histogram_with_bounds(
&self,
key: &str,
help: &str,
bounds_us: &[u64],
) -> Arc<Histogram>
pub fn histogram_with_bounds( &self, key: &str, help: &str, bounds_us: &[u64], ) -> Arc<Histogram>
Register (or fetch) a histogram with explicit bucket bounds. Use
WIDE_LATENCY_BOUNDS_US for spans dominated by network I/O
(upstream LLM streaming, reconciler filesystem scans); use
DEFAULT_LATENCY_BOUNDS_US for fast internal stages.
Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Render the registry in Prometheus text exposition format.
Histogram observations are stored internally in microseconds but
rendered in seconds (le bounds and _sum), per Prometheus base-unit
convention. Histogram metric names should therefore end in _seconds.
Round-19: HELP text is escaped per the Prometheus text format
spec (\ → \\, LF → \n). A future counter/histogram
registration whose HELP contained a newline would otherwise
silently corrupt the scrape response — Prometheus would parse
the remainder of the HELP text as metric samples and fail.