69
69
import re
70
70
from typing import Iterable , Optional , Sequence , Union
71
71
72
+ from prometheus_client .core import (
73
+ REGISTRY ,
74
+ CounterMetricFamily ,
75
+ SummaryMetricFamily ,
76
+ UnknownMetricFamily ,
77
+ )
78
+
72
79
from opentelemetry .metrics import Counter , ValueRecorder
73
80
from opentelemetry .sdk .metrics .export import (
74
81
MetricRecord ,
75
82
MetricsExporter ,
76
83
MetricsExportResult ,
77
84
)
78
85
from opentelemetry .sdk .metrics .export .aggregate import MinMaxSumCountAggregator
79
- from prometheus_client .core import (
80
- REGISTRY ,
81
- CounterMetricFamily ,
82
- SummaryMetricFamily ,
83
- UnknownMetricFamily ,
84
- )
85
86
86
87
logger = logging .getLogger (__name__ )
87
88
@@ -123,11 +124,7 @@ def __init__(self, prefix: str = ""):
123
124
def add_metrics_data (self , metric_records : Sequence [MetricRecord ]) -> None :
124
125
self ._metrics_to_export .append (metric_records )
125
126
126
- def collect (
127
- self ,
128
- ) -> Iterable [
129
- Union [CounterMetricFamily , SummaryMetricFamily , UnknownMetricFamily ]
130
- ]:
127
+ def collect (self ):
131
128
"""Collect fetches the metrics from OpenTelemetry
132
129
and delivers them as Prometheus Metrics.
133
130
Collect is invoked every time a prometheus.Gatherer is run
@@ -142,11 +139,7 @@ def collect(
142
139
if prometheus_metric is not None :
143
140
yield prometheus_metric
144
141
145
- def _translate_to_prometheus (
146
- self , metric_record : MetricRecord
147
- ) -> Optional [
148
- Union [CounterMetricFamily , SummaryMetricFamily , UnknownMetricFamily ]
149
- ]:
142
+ def _translate_to_prometheus (self , metric_record : MetricRecord ):
150
143
prometheus_metric = None
151
144
label_values = []
152
145
label_keys = []
@@ -170,7 +163,9 @@ def _translate_to_prometheus(
170
163
# TODO: Add support for histograms when supported in OT
171
164
elif isinstance (metric_record .instrument , ValueRecorder ):
172
165
value = metric_record .aggregator .checkpoint
173
- if isinstance (value , MinMaxSumCountAggregator ._TYPE ):
166
+ if isinstance (
167
+ value , MinMaxSumCountAggregator ._TYPE # pylint: disable=W0212
168
+ ):
174
169
value = metric_record .aggregator .checkpoint
175
170
prometheus_metric = SummaryMetricFamily (
176
171
name = metric_name ,
0 commit comments