Repository: envoyproxy/envoy
File: source/extensions/stat_sinks/open_telemetry/open_telemetry_impl.cc (C++)

Code before:
          getCombinedAttributes(counter.counter_.get(), metric_config_result.conversion_action);
      aggregator.addCounter(metric_name, counter.counter_.get().value(), counter.delta_,
                            counter_temporality, attributes);
    }
  }
  for (const auto& counter : snapshot.hostCounters()) {
    auto metric_config_result = getMetricConfig(counter);
    if (metric_config_result.drop_stat)
      continue;

    const std::string metric_name = getMetricName(counter, metric_config_result.conversion_action);
    auto attributes = getCombinedAttributes(counter, metric_config_result.conversion_action);
    aggregator.addCounter(metric_name, counter.value(), counter.delta(), counter_temporality,
                          attributes);
  }

  // Process Histograms
  AggregationTemporality histogram_temporality =
      config_->reportHistogramsAsDeltas()
          ? AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA
          : AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE;
  for (const auto& histogram : snapshot.histograms()) {
    if (predicate_(histogram)) {
      auto metric_config_result = getMetricConfig(histogram.get());
      if (metric_config_result.drop_stat)
        continue;

      const std::string metric_name =
          getMetricName(histogram.get(), metric_config_result.conversion_action);
      auto attributes =
          getCombinedAttributes(histogram.get(), metric_config_result.conversion_action);
      const Stats::HistogramStatistics& histogram_stats =
          config_->reportHistogramsAsDeltas() ? histogram.get().intervalStatistics()
                                              : histogram.get().cumulativeStatistics();
      aggregator.addHistogram(histogram.get().name(), metric_name, histogram_stats,
                              histogram_temporality, attributes);
    }
  }
  // Add all aggregated metrics to the request.
  *request->mutable_resource_metrics() =
      aggregator.getResourceMetrics(config_->resource_attributes());
  return request;
}
} // namespace OpenTelemetry
} // namespace StatSinks
} // namespace Extensions
} // namespace Envoy


Review comment (suggestion):
ditto.

And I think you can keep the variable name be `metric_config`. The drop action absolutely is also part of the configuration.
Then we chan reduce unnecessary code change and make the review easier.

Code after:
          getMetricName(counter.counter_.get(), metric_config.conversion_action);
      auto attributes =
          getCombinedAttributes(counter.counter_.get(), metric_config.conversion_action);
      aggregator.addCounter(metric_name, counter.counter_.get().value(), counter.delta_,
                            counter_temporality, attributes);
    }
  }
  for (const auto& counter : snapshot.hostCounters()) {
    auto metric_config = getMetricConfig(counter);
    if (metric_config.drop_stat) {
      continue;
    }

    const std::string metric_name = getMetricName(counter, metric_config.conversion_action);
    auto attributes = getCombinedAttributes(counter, metric_config.conversion_action);
    aggregator.addCounter(metric_name, counter.value(), counter.delta(), counter_temporality,
                          attributes);
  }

  // Process Histograms
  AggregationTemporality histogram_temporality =
      config_->reportHistogramsAsDeltas()
          ? AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA
          : AggregationTemporality::AGGREGATION_TEMPORALITY_CUMULATIVE;
  for (const auto& histogram : snapshot.histograms()) {
    if (predicate_(histogram)) {
      auto metric_config = getMetricConfig(histogram.get());
      if (metric_config.drop_stat) {
        continue;
      }

      const std::string metric_name =
          getMetricName(histogram.get(), metric_config.conversion_action);
      auto attributes = getCombinedAttributes(histogram.get(), metric_config.conversion_action);
      const Stats::HistogramStatistics& histogram_stats =
          config_->reportHistogramsAsDeltas() ? histogram.get().intervalStatistics()
                                              : histogram.get().cumulativeStatistics();
      aggregator.addHistogram(histogram.get().name(), metric_name, histogram_stats,
                              histogram_temporality, attributes);
    }
  }
  // Add all aggregated metrics to the request.
  *request->mutable_resource_metrics() =
      aggregator.getResourceMetrics(config_->resource_attributes());
  return request;
}
} // namespace OpenTelemetry
} // namespace StatSinks
} // namespace Extensions
} // namespace Envoy