Skip to content

Commit 4a014e3

Browse files
committed
Fix CollectorRegistry import and test assertion
1 parent 9436348 commit 4a014e3

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
from os import environ
7070
from typing import Deque, Dict, Iterable, Sequence, Tuple, Union
7171

72-
from prometheus_client import start_http_server
72+
from prometheus_client import CollectorRegistry, start_http_server
7373
from prometheus_client.core import (
7474
REGISTRY,
7575
CounterMetricFamily,

exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ def setUp(self):
5656
)
5757

5858
def test_custom_registry(self):
59-
custom_registry = CollectorRegistry()
60-
reader = PrometheusMetricReader(registry=custom_registry)
61-
# global REGISTRY should NOT be used
62-
self._mock_registry_register.assert_not_called()
63-
# check custom_registry was registered
64-
self.assertIn(reader._collector, custom_registry._names_to_collectors.values())
65-
reader.shutdown()
59+
with self._registry_register_patch:
60+
custom_registry = CollectorRegistry()
61+
reader = PrometheusMetricReader(registry=custom_registry)
62+
# global REGISTRY should NOT be used
63+
self._mock_registry_register.assert_not_called()
64+
# check custom_registry was registered
65+
self.assertIn(reader._collector, custom_registry._collector_to_names)
66+
reader.shutdown()
67+
68+
6669

6770
def verify_text_format(
6871
self, metric: Metric, expect_prometheus_text: str, prefix: str = ""

0 commit comments

Comments
 (0)