@@ -246,29 +246,50 @@ def as_otlp_metrics(metrics)
246246 )
247247
248248 when :histogram
249+ histogram_data_point ( metrics )
250+
251+ end
252+ end
253+
254+ def as_otlp_aggregation_temporality ( type )
255+ case type
256+ when :delta then Opentelemetry ::Proto ::Metrics ::V1 ::AggregationTemporality ::AGGREGATION_TEMPORALITY_DELTA
257+ when :cumulative then Opentelemetry ::Proto ::Metrics ::V1 ::AggregationTemporality ::AGGREGATION_TEMPORALITY_CUMULATIVE
258+ else Opentelemetry ::Proto ::Metrics ::V1 ::AggregationTemporality ::AGGREGATION_TEMPORALITY_UNSPECIFIED
259+ end
260+ end
261+
262+ def histogram_data_point ( metrics )
263+ return if metrics . data_points . empty?
264+
265+ if metrics . data_points . first . instance_of? ( OpenTelemetry ::SDK ::Metrics ::Aggregation ::ExponentialHistogramDataPoint )
266+ Opentelemetry ::Proto ::Metrics ::V1 ::Metric . new (
267+ name : metrics . name ,
268+ description : metrics . description ,
269+ unit : metrics . unit ,
270+ exponential_histogram : Opentelemetry ::Proto ::Metrics ::V1 ::ExponentialHistogram . new (
271+ aggregation_temporality : as_otlp_aggregation_temporality ( metrics . aggregation_temporality ) ,
272+ data_points : metrics . data_points . map do |ehdp |
273+ exponential_histogram_data_point ( ehdp )
274+ end
275+ )
276+ )
277+ elsif metrics . data_points . first . instance_of? ( OpenTelemetry ::SDK ::Metrics ::Aggregation ::HistogramDataPoint )
249278 Opentelemetry ::Proto ::Metrics ::V1 ::Metric . new (
250279 name : metrics . name ,
251280 description : metrics . description ,
252281 unit : metrics . unit ,
253282 histogram : Opentelemetry ::Proto ::Metrics ::V1 ::Histogram . new (
254283 aggregation_temporality : as_otlp_aggregation_temporality ( metrics . aggregation_temporality ) ,
255284 data_points : metrics . data_points . map do |hdp |
256- histogram_data_point ( hdp )
285+ explicit_histogram_data_point ( hdp )
257286 end
258287 )
259288 )
260289 end
261290 end
262291
263- def as_otlp_aggregation_temporality ( type )
264- case type
265- when :delta then Opentelemetry ::Proto ::Metrics ::V1 ::AggregationTemporality ::AGGREGATION_TEMPORALITY_DELTA
266- when :cumulative then Opentelemetry ::Proto ::Metrics ::V1 ::AggregationTemporality ::AGGREGATION_TEMPORALITY_CUMULATIVE
267- else Opentelemetry ::Proto ::Metrics ::V1 ::AggregationTemporality ::AGGREGATION_TEMPORALITY_UNSPECIFIED
268- end
269- end
270-
271- def histogram_data_point ( hdp )
292+ def explicit_histogram_data_point ( hdp )
272293 Opentelemetry ::Proto ::Metrics ::V1 ::HistogramDataPoint . new (
273294 attributes : hdp . attributes . map { |k , v | as_otlp_key_value ( k , v ) } ,
274295 start_time_unix_nano : hdp . start_time_unix_nano ,
@@ -283,6 +304,31 @@ def histogram_data_point(hdp)
283304 )
284305 end
285306
307+ def exponential_histogram_data_point ( ehdp )
308+ Opentelemetry ::Proto ::Metrics ::V1 ::ExponentialHistogramDataPoint . new (
309+ attributes : ehdp . attributes . map { |k , v | as_otlp_key_value ( k , v ) } ,
310+ start_time_unix_nano : ehdp . start_time_unix_nano ,
311+ time_unix_nano : ehdp . time_unix_nano ,
312+ count : ehdp . count ,
313+ sum : ehdp . sum ,
314+ scale : ehdp . scale ,
315+ zero_count : ehdp . zero_count ,
316+ positive : Opentelemetry ::Proto ::Metrics ::V1 ::ExponentialHistogramDataPoint ::Buckets . new (
317+ offset : ehdp . positive . offset ,
318+ bucket_counts : ehdp . positive . counts
319+ ) ,
320+ negative : Opentelemetry ::Proto ::Metrics ::V1 ::ExponentialHistogramDataPoint ::Buckets . new (
321+ offset : ehdp . negative . offset ,
322+ bucket_counts : ehdp . negative . counts
323+ ) ,
324+ flags : ehdp . flags ,
325+ exemplars : ehdp . exemplars ,
326+ min : ehdp . min ,
327+ max : ehdp . max ,
328+ zero_threshold : ehdp . zero_threshold
329+ )
330+ end
331+
286332 def number_data_point ( ndp )
287333 args = {
288334 attributes : ndp . attributes . map { |k , v | as_otlp_key_value ( k , v ) } ,
0 commit comments