Skip to content

Commit

Permalink
Merge branch 'main' into release_1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Jan 22, 2025
2 parents 8f9b4a0 + e216555 commit 3020f34
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions sdk/src/metrics/state/temporal_metric_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,35 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector,
AggregationTemporality aggregation_temporarily =
collector->GetAggregationTemporality(instrument_descriptor_.type_);

// Fast path for single collector with delta temporality and counter, updown-counter, histogram
// This path doesn't need to aggregated-with/contribute-to the unreported_metric_, as there is
// no other reader configured to collect those data.
if (collectors.size() == 1 && aggregation_temporarily == AggregationTemporality::kDelta)
{
// If no metrics, early return
if (delta_metrics->Size() == 0)
{
return true;
}
// Create MetricData directly
MetricData metric_data;
metric_data.instrument_descriptor = instrument_descriptor_;
metric_data.aggregation_temporality = AggregationTemporality::kDelta;
metric_data.start_ts = sdk_start_ts;
metric_data.end_ts = collection_ts;

// Direct conversion of delta metrics to point data
delta_metrics->GetAllEnteries(
[&metric_data](const MetricAttributes &attributes, Aggregation &aggregation) {
PointDataAttributes point_data_attr;
point_data_attr.point_data = aggregation.ToPoint();
point_data_attr.attributes = attributes;
metric_data.point_data_attr_.emplace_back(std::move(point_data_attr));
return true;
});
return callback(metric_data);
}

if (delta_metrics->Size())
{
for (auto &col : collectors)
Expand Down

0 comments on commit 3020f34

Please sign in to comment.