Skip to content

Commit

Permalink
minor metrics handling optimizations (#1890)
Browse files Browse the repository at this point in the history
  • Loading branch information
ays7 authored Jan 3, 2023
1 parent 9197bf3 commit d5f0c48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions sdk/src/metrics/state/metric_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ bool MetricCollector::Collect(
ResourceMetrics resource_metrics;
meter_context_->ForEachMeter([&](std::shared_ptr<Meter> meter) noexcept {
auto collection_ts = std::chrono::system_clock::now();
ScopeMetrics scope_metrics;
scope_metrics.metric_data_ = meter->Collect(this, collection_ts);
scope_metrics.scope_ = meter->GetInstrumentationScope();
resource_metrics.scope_metric_data_.push_back(scope_metrics);
auto metric_data = meter->Collect(this, collection_ts);
if (!metric_data.empty())
{
ScopeMetrics scope_metrics;
scope_metrics.metric_data_ = std::move(metric_data);
scope_metrics.scope_ = meter->GetInstrumentationScope();
resource_metrics.scope_metric_data_.emplace_back(std::move(scope_metrics));
}
return true;
});
resource_metrics.resource_ = &meter_context_->GetResource();
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/metrics/state/temporal_metric_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector,
PointDataAttributes point_data_attr;
point_data_attr.point_data = aggregation.ToPoint();
point_data_attr.attributes = attributes;
metric_data.point_data_attr_.push_back(point_data_attr);
metric_data.point_data_attr_.emplace_back(std::move(point_data_attr));
return true;
});
return callback(metric_data);
Expand Down

0 comments on commit d5f0c48

Please sign in to comment.