54
54
ValueRecorder ,
55
55
)
56
56
from opentelemetry .sdk .metrics .export import (
57
- MetricRecord ,
57
+ ExportRecord ,
58
58
MetricsExporter ,
59
59
MetricsExportResult ,
60
60
)
71
71
72
72
73
73
def _get_data_points (
74
- sdk_metric_record : MetricRecord , data_point_class : Type [DataPointT ]
74
+ export_record : ExportRecord , data_point_class : Type [DataPointT ]
75
75
) -> List [DataPointT ]:
76
76
77
- if isinstance (sdk_metric_record .aggregator , SumAggregator ):
78
- value = sdk_metric_record .aggregator .checkpoint
77
+ if isinstance (export_record .aggregator , SumAggregator ):
78
+ value = export_record .aggregator .checkpoint
79
79
80
- elif isinstance (sdk_metric_record .aggregator , MinMaxSumCountAggregator ):
80
+ elif isinstance (export_record .aggregator , MinMaxSumCountAggregator ):
81
81
# FIXME: How are values to be interpreted from this aggregator?
82
82
raise Exception ("MinMaxSumCount aggregator data not supported" )
83
83
84
- elif isinstance (sdk_metric_record .aggregator , HistogramAggregator ):
84
+ elif isinstance (export_record .aggregator , HistogramAggregator ):
85
85
# FIXME: How are values to be interpreted from this aggregator?
86
86
raise Exception ("Histogram aggregator data not supported" )
87
87
88
- elif isinstance (sdk_metric_record .aggregator , LastValueAggregator ):
89
- value = sdk_metric_record .aggregator .checkpoint
88
+ elif isinstance (export_record .aggregator , LastValueAggregator ):
89
+ value = export_record .aggregator .checkpoint
90
90
91
- elif isinstance (sdk_metric_record .aggregator , ValueObserverAggregator ):
92
- value = sdk_metric_record .aggregator .checkpoint .last
91
+ elif isinstance (export_record .aggregator , ValueObserverAggregator ):
92
+ value = export_record .aggregator .checkpoint .last
93
93
94
94
return [
95
95
data_point_class (
96
96
labels = [
97
97
StringKeyValue (key = str (label_key ), value = str (label_value ))
98
- for label_key , label_value in sdk_metric_record .labels
98
+ for label_key , label_value in export_record .labels
99
99
],
100
100
value = value ,
101
101
start_time_unix_nano = (
102
- sdk_metric_record .aggregator .initial_checkpoint_timestamp
103
- ),
104
- time_unix_nano = (
105
- sdk_metric_record .aggregator .last_update_timestamp
102
+ export_record .aggregator .initial_checkpoint_timestamp
106
103
),
104
+ time_unix_nano = (export_record .aggregator .last_update_timestamp ),
107
105
)
108
106
]
109
107
110
108
111
109
class OTLPMetricsExporter (
112
110
MetricsExporter ,
113
111
OTLPExporterMixin [
114
- MetricRecord , ExportMetricsServiceRequest , MetricsExportResult
112
+ ExportRecord , ExportMetricsServiceRequest , MetricsExportResult
115
113
],
116
114
):
117
115
# pylint: disable=unsubscriptable-object
@@ -162,14 +160,14 @@ def __init__(
162
160
163
161
# pylint: disable=no-self-use
164
162
def _translate_data (
165
- self , data : Sequence [MetricRecord ]
163
+ self , export_records : Sequence [ExportRecord ]
166
164
) -> ExportMetricsServiceRequest :
167
165
# pylint: disable=too-many-locals,no-member
168
166
# pylint: disable=attribute-defined-outside-init
169
167
170
168
sdk_resource_instrumentation_library_metrics = {}
171
169
172
- # The criteria to decide how to translate data is based on this table
170
+ # The criteria to decide how to translate export_records is based on this table
173
171
# taken directly from OpenTelemetry Proto v0.5.0:
174
172
175
173
# TODO: Update table after the decision on:
@@ -185,13 +183,13 @@ def _translate_data(
185
183
# SumObserver Sum(aggregation_temporality=cumulative;is_monotonic=true)
186
184
# UpDownSumObserver Sum(aggregation_temporality=cumulative;is_monotonic=false)
187
185
# ValueObserver Gauge()
188
- for sdk_metric_record in data :
186
+ for export_record in export_records :
189
187
190
- if sdk_metric_record .resource not in (
188
+ if export_record .resource not in (
191
189
sdk_resource_instrumentation_library_metrics .keys ()
192
190
):
193
191
sdk_resource_instrumentation_library_metrics [
194
- sdk_metric_record .resource
192
+ export_record .resource
195
193
] = InstrumentationLibraryMetrics ()
196
194
197
195
type_class = {
@@ -210,16 +208,16 @@ def _translate_data(
210
208
},
211
209
}
212
210
213
- value_type = sdk_metric_record .instrument .value_type
211
+ value_type = export_record .instrument .value_type
214
212
215
213
sum_class = type_class [value_type ]["sum" ]["class" ]
216
214
gauge_class = type_class [value_type ]["gauge" ]["class" ]
217
215
data_point_class = type_class [value_type ]["data_point_class" ]
218
216
219
- if isinstance (sdk_metric_record .instrument , Counter ):
217
+ if isinstance (export_record .instrument , Counter ):
220
218
otlp_metric_data = sum_class (
221
219
data_points = _get_data_points (
222
- sdk_metric_record , data_point_class
220
+ export_record , data_point_class
223
221
),
224
222
aggregation_temporality = (
225
223
AggregationTemporality .AGGREGATION_TEMPORALITY_DELTA
@@ -228,10 +226,10 @@ def _translate_data(
228
226
)
229
227
argument = type_class [value_type ]["sum" ]["argument" ]
230
228
231
- elif isinstance (sdk_metric_record .instrument , UpDownCounter ):
229
+ elif isinstance (export_record .instrument , UpDownCounter ):
232
230
otlp_metric_data = sum_class (
233
231
data_points = _get_data_points (
234
- sdk_metric_record , data_point_class
232
+ export_record , data_point_class
235
233
),
236
234
aggregation_temporality = (
237
235
AggregationTemporality .AGGREGATION_TEMPORALITY_DELTA
@@ -240,14 +238,14 @@ def _translate_data(
240
238
)
241
239
argument = type_class [value_type ]["sum" ]["argument" ]
242
240
243
- elif isinstance (sdk_metric_record .instrument , (ValueRecorder )):
241
+ elif isinstance (export_record .instrument , (ValueRecorder )):
244
242
logger .warning ("Skipping exporting of ValueRecorder metric" )
245
243
continue
246
244
247
- elif isinstance (sdk_metric_record .instrument , SumObserver ):
245
+ elif isinstance (export_record .instrument , SumObserver ):
248
246
otlp_metric_data = sum_class (
249
247
data_points = _get_data_points (
250
- sdk_metric_record , data_point_class
248
+ export_record , data_point_class
251
249
),
252
250
aggregation_temporality = (
253
251
AggregationTemporality .AGGREGATION_TEMPORALITY_CUMULATIVE
@@ -256,10 +254,10 @@ def _translate_data(
256
254
)
257
255
argument = type_class [value_type ]["sum" ]["argument" ]
258
256
259
- elif isinstance (sdk_metric_record .instrument , UpDownSumObserver ):
257
+ elif isinstance (export_record .instrument , UpDownSumObserver ):
260
258
otlp_metric_data = sum_class (
261
259
data_points = _get_data_points (
262
- sdk_metric_record , data_point_class
260
+ export_record , data_point_class
263
261
),
264
262
aggregation_temporality = (
265
263
AggregationTemporality .AGGREGATION_TEMPORALITY_CUMULATIVE
@@ -268,24 +266,22 @@ def _translate_data(
268
266
)
269
267
argument = type_class [value_type ]["sum" ]["argument" ]
270
268
271
- elif isinstance (sdk_metric_record .instrument , (ValueObserver )):
269
+ elif isinstance (export_record .instrument , (ValueObserver )):
272
270
otlp_metric_data = gauge_class (
273
271
data_points = _get_data_points (
274
- sdk_metric_record , data_point_class
272
+ export_record , data_point_class
275
273
)
276
274
)
277
275
argument = type_class [value_type ]["gauge" ]["argument" ]
278
276
279
277
sdk_resource_instrumentation_library_metrics [
280
- sdk_metric_record .resource
278
+ export_record .resource
281
279
].metrics .append (
282
280
OTLPMetric (
283
281
** {
284
- "name" : sdk_metric_record .instrument .name ,
285
- "description" : (
286
- sdk_metric_record .instrument .description
287
- ),
288
- "unit" : sdk_metric_record .instrument .unit ,
282
+ "name" : export_record .instrument .name ,
283
+ "description" : (export_record .instrument .description ),
284
+ "unit" : export_record .instrument .unit ,
289
285
argument : otlp_metric_data ,
290
286
}
291
287
)
@@ -299,6 +295,6 @@ def _translate_data(
299
295
)
300
296
)
301
297
302
- def export (self , metrics : Sequence [MetricRecord ]) -> MetricsExportResult :
298
+ def export (self , metrics : Sequence [ExportRecord ]) -> MetricsExportResult :
303
299
# pylint: disable=arguments-differ
304
300
return self ._export (metrics )
0 commit comments