From 46a5505ac6b3c70fb436dd2dc7a1a97072f51f0c Mon Sep 17 00:00:00 2001 From: Mariana Souza Date: Wed, 15 Jan 2025 15:40:18 -0300 Subject: [PATCH] dry and test --- .../exporter/otlp/metrics/metrics_exporter.rb | 16 +------------ .../otlp/metrics/metrics_exporter_test.rb | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb index 21caff7a7..57afe2a23 100644 --- a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb +++ b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb @@ -231,21 +231,7 @@ def as_otlp_metrics(metrics) ) ) - when :up_down_counter - Opentelemetry::Proto::Metrics::V1::Metric.new( - name: metrics.name, - description: metrics.description, - unit: metrics.unit, - sum: Opentelemetry::Proto::Metrics::V1::Sum.new( - aggregation_temporality: as_otlp_aggregation_temporality(metrics.aggregation_temporality), - data_points: metrics.data_points.map do |ndp| - number_data_point(ndp) - end, - is_monotonic: metrics.is_monotonic - ) - ) - - when :counter + when :counter, :up_down_counter Opentelemetry::Proto::Metrics::V1::Metric.new( name: metrics.name, description: metrics.description, diff --git a/exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb b/exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb index 7000396f6..8819bd36c 100644 --- a/exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb +++ b/exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb @@ -580,6 +580,9 @@ counter = meter.create_counter('test_counter', unit: 'smidgen', description: 'a small amount of something') counter.add(5, attributes: { 'foo' => 'bar' }) + up_down_counter = meter.create_up_down_counter('test_up_down_counter', unit: 'smidgen', description: 'a small amount of something') + up_down_counter.add(5, attributes: { 'foo' => 'bar' }) + histogram = meter.create_histogram('test_histogram', unit: 'smidgen', description: 'a small amount of something') histogram.record(10, attributes: { 'oof' => 'rab' }) @@ -627,6 +630,26 @@ aggregation_temporality: Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA ) ), + Opentelemetry::Proto::Metrics::V1::Metric.new( + name: 'test_up_down_counter', + description: 'a small amount of something', + unit: 'smidgen', + sum: Opentelemetry::Proto::Metrics::V1::Sum.new( + data_points: [ + Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new( + attributes: [ + Opentelemetry::Proto::Common::V1::KeyValue.new(key: 'foo', value: Opentelemetry::Proto::Common::V1::AnyValue.new(string_value: 'bar')) + ], + as_int: 5, + start_time_unix_nano: 1_699_593_427_329_946_585, + time_unix_nano: 1_699_593_427_329_946_586, + exemplars: nil + ) + ], + is_monotonic: false, + aggregation_temporality: Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA + ) + ), Opentelemetry::Proto::Metrics::V1::Metric.new( name: 'test_histogram', description: 'a small amount of something',