Skip to content

Commit

Permalink
[EXPORTER] Fix Aggregation type detection in OTLP Exporter (#2467)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Dec 22, 2023
1 parent e8afbb8 commit 0dd5eed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 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::sdk::metrics::MetricData &metric_data) noexcept;

static proto::metrics::v1::AggregationTemporality GetProtoAggregationTemporality(
const opentelemetry::sdk::metrics::AggregationTemporality &aggregation_temporality) noexcept;
Expand Down
21 changes: 12 additions & 9 deletions exporters/otlp/src/otlp_metric_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
}
Expand Down Expand Up @@ -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: {
Expand Down

1 comment on commit 0dd5eed

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 0dd5eed Previous: e8afbb8 Ratio
BM_LockFreeBuffer/2 9680154.32357788 ns/iter 1750743.9985061986 ns/iter 5.53

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.