diff --git a/prometheus_client/registry.py b/prometheus_client/registry.py index 4326b39a..5e282b62 100644 --- a/prometheus_client/registry.py +++ b/prometheus_client/registry.py @@ -18,6 +18,14 @@ def collect(self) -> Iterable[Metric]: return [] +class DuplicateTimeseries(ValueError): + def __init__(self, duplicates): + msg = 'Duplicated timeseries in CollectorRegistry: {}'.format( + duplicates) + super().__init__(msg) + self.duplicates = duplicates + + class CollectorRegistry(Collector): """Metric collector registry. @@ -40,9 +48,7 @@ def register(self, collector: Collector) -> None: names = self._get_names(collector) duplicates = set(self._names_to_collectors).intersection(names) if duplicates: - raise ValueError( - 'Duplicated timeseries in CollectorRegistry: {}'.format( - duplicates)) + raise DuplicateTimeseries(duplicates) for name in names: self._names_to_collectors[name] = collector self._collector_to_names[collector] = names