From 638e9e85f440b03ba8c267250199829f4aa4527a Mon Sep 17 00:00:00 2001 From: g4lb Date: Wed, 18 Nov 2026 09:16:29 +0200 Subject: [PATCH] Inline the observable check in _raise_if_not_observable Signed-off-by: g4lb --- prometheus_client/metrics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prometheus_client/metrics.py b/prometheus_client/metrics.py index a0ad9b92..8a96c000 100644 --- a/prometheus_client/metrics.py +++ b/prometheus_client/metrics.py @@ -75,7 +75,8 @@ def _raise_if_not_observable(self): # Functions that mutate the state of the metric, for example incrementing # a counter, will fail if the metric is not observable, because only if a # metric is observable will the value be initialized. - if not self._is_observable(): + # This is the inverse of _is_observable(), inlined as it runs on every update. + if self._labelnames and not self._labelvalues: raise ValueError('%s metric is missing label values' % str(self._type)) def _is_parent(self):