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 36705bbf7..d2beac6d5 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 @@ -214,18 +214,17 @@ def encode(metrics_data) end # metrics_pb has following type of data: :gauge, :sum, :histogram, :exponential_histogram, :summary - # current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram + # current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram, :gauge -> :gauge # # metrics [MetricData] def as_otlp_metrics(metrics) case metrics.instrument_kind - when :observable_gauge + when :observable_gauge, :gauge Opentelemetry::Proto::Metrics::V1::Metric.new( name: metrics.name, description: metrics.description, unit: metrics.unit, gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new( - aggregation_temporality: as_otlp_aggregation_temporality(metrics.aggregation_temporality), data_points: metrics.data_points.map do |ndp| number_data_point(ndp) end 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 6076a80a2..020d0e9a8 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 @@ -576,11 +576,16 @@ stub_request(:post, 'http://localhost:4318/v1/metrics').to_return(status: 200) meter_provider.add_metric_reader(exporter) meter = meter_provider.meter('test') + counter = meter.create_counter('test_counter', unit: 'smidgen', description: 'a small amount of something') 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' }) + + gauge = meter.create_gauge('test_gauge', unit: 'smidgen', description: 'a small amount of something') + gauge.record(15, attributes: { 'baz' => 'qux' }) + exporter.pull meter_provider.shutdown @@ -644,6 +649,24 @@ ], aggregation_temporality: Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA ) + ), + Opentelemetry::Proto::Metrics::V1::Metric.new( + name: 'test_gauge', + description: 'a small amount of something', + unit: 'smidgen', + gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new( + data_points: [ + Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new( + attributes: [ + Opentelemetry::Proto::Common::V1::KeyValue.new(key: 'baz', value: Opentelemetry::Proto::Common::V1::AnyValue.new(string_value: 'qux')) + ], + as_int: 15, + start_time_unix_nano: 1_699_593_427_329_946_585, + time_unix_nano: 1_699_593_427_329_946_586, + exemplars: nil + ) + ] + ) ) ] ) diff --git a/exporter/otlp-metrics/test/test_helper.rb b/exporter/otlp-metrics/test/test_helper.rb index 9fc446645..4d3e4df6d 100644 --- a/exporter/otlp-metrics/test/test_helper.rb +++ b/exporter/otlp-metrics/test/test_helper.rb @@ -26,6 +26,7 @@ def collect(start_time, end_time, data_points) OpenTelemetry::SDK::Metrics::Aggregation::Sum.prepend(MockSum) OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram.prepend(MockSum) +OpenTelemetry::SDK::Metrics::Aggregation::LastValue.prepend(MockSum) def create_metrics_data(name: '', description: '', unit: '', instrument_kind: :counter, resource: nil, instrumentation_scope: OpenTelemetry::SDK::InstrumentationScope.new('', 'v0.0.1'),