diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h index 1adca861d8..c6e11aeff3 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h @@ -26,7 +26,7 @@ class OtlpMetricUtils { public: static opentelemetry::sdk::metrics::AggregationType GetAggregationType( - const opentelemetry::sdk::metrics::InstrumentType &instrument_type) noexcept; + const opentelemetry::sdk::metrics::MetricData &metric_data) noexcept; static proto::metrics::v1::AggregationTemporality GetProtoAggregationTemporality( const opentelemetry::sdk::metrics::AggregationTemporality &aggregation_temporality) noexcept; diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index 50c5fdd9cc..ed1620a56c 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -25,21 +25,24 @@ proto::metrics::v1::AggregationTemporality OtlpMetricUtils::GetProtoAggregationT } metric_sdk::AggregationType OtlpMetricUtils::GetAggregationType( - const opentelemetry::sdk::metrics::InstrumentType &instrument_type) noexcept + const opentelemetry::sdk::metrics::MetricData &metric_data) noexcept { - - if (instrument_type == metric_sdk::InstrumentType::kCounter || - instrument_type == metric_sdk::InstrumentType::kUpDownCounter || - instrument_type == metric_sdk::InstrumentType::kObservableCounter || - instrument_type == metric_sdk::InstrumentType::kObservableUpDownCounter) + if (metric_data.point_data_attr_.size() == 0) + { + return metric_sdk::AggregationType::kDrop; + } + auto point_data_with_attributes = metric_data.point_data_attr_[0]; + if (nostd::holds_alternative(point_data_with_attributes.point_data)) { return metric_sdk::AggregationType::kSum; } - else if (instrument_type == metric_sdk::InstrumentType::kHistogram) + else if (nostd::holds_alternative( + point_data_with_attributes.point_data)) { return metric_sdk::AggregationType::kHistogram; } - else if (instrument_type == metric_sdk::InstrumentType::kObservableGauge) + else if (nostd::holds_alternative( + point_data_with_attributes.point_data)) { return metric_sdk::AggregationType::kLastValue; } @@ -188,7 +191,7 @@ void OtlpMetricUtils::PopulateInstrumentInfoMetrics( metric->set_name(metric_data.instrument_descriptor.name_); metric->set_description(metric_data.instrument_descriptor.description_); metric->set_unit(metric_data.instrument_descriptor.unit_); - auto kind = GetAggregationType(metric_data.instrument_descriptor.type_); + auto kind = GetAggregationType(metric_data); switch (kind) { case metric_sdk::AggregationType::kSum: {