Skip to content

Commit

Permalink
fix aggregation change through view
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Dec 21, 2023
1 parent e8afbb8 commit bbb9502
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OtlpMetricUtils
{
public:
static opentelemetry::sdk::metrics::AggregationType GetAggregationType(
const opentelemetry::sdk::metrics::InstrumentType &instrument_type) noexcept;
const opentelemetry::v1::sdk::metrics::MetricData &metric_data) noexcept;

static proto::metrics::v1::AggregationTemporality GetProtoAggregationTemporality(
const opentelemetry::sdk::metrics::AggregationTemporality &aggregation_temporality) noexcept;
Expand Down
22 changes: 12 additions & 10 deletions exporters/otlp/src/otlp_metric_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ proto::metrics::v1::AggregationTemporality OtlpMetricUtils::GetProtoAggregationT
}

metric_sdk::AggregationType OtlpMetricUtils::GetAggregationType(
const opentelemetry::sdk::metrics::InstrumentType &instrument_type) noexcept
const opentelemetry::v1::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<sdk::metrics::SumPointData>(point_data_with_attributes.point_data))
{
return metric_sdk::AggregationType::kSum;
}
else if (instrument_type == metric_sdk::InstrumentType::kHistogram)
else if (nostd::holds_alternative<sdk::metrics::HistogramPointData>(
point_data_with_attributes.point_data))
{
return metric_sdk::AggregationType::kHistogram;
}
else if (instrument_type == metric_sdk::InstrumentType::kObservableGauge)
else if (nostd::holds_alternative<sdk::metrics::LastValuePointData>(
point_data_with_attributes.point_data))
{
return metric_sdk::AggregationType::kLastValue;
}
return metric_sdk::AggregationType::kDrop;
}

void OtlpMetricUtils::ConvertSumMetric(const metric_sdk::MetricData &metric_data,
Expand Down Expand Up @@ -188,7 +190,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: {
Expand Down

0 comments on commit bbb9502

Please sign in to comment.