From 3dc902c705348ddd03aba98f92906015d2e8ed9b Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Mon, 18 Sep 2023 15:43:09 +0000 Subject: [PATCH] address comments --- exporters/prometheus/src/exporter_utils.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index f20ba5ef9e..8a577f689b 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -276,7 +276,7 @@ void PrometheusExporterUtils::SetMetricBasic( size_t i = 0; if (!labels.empty()) { - metric.label.resize(labels.size()); + metric.label.reserve(labels.size() + 2); for (auto const &label : labels) { auto sanitized = SanitizeNames(label.first); @@ -284,17 +284,16 @@ void PrometheusExporterUtils::SetMetricBasic( metric.label[i++].value = AttributeValueToString(label.second); } } + if (!scope) return; auto scope_name = scope->GetName(); if (!scope_name.empty()) { - metric.label.resize(i + 1); metric.label[i].name = "otel_scope_name"; metric.label[i++].value = scope_name; } auto scope_version = scope->GetVersion(); if (!scope_version.empty()) { - metric.label.resize(i + 1); metric.label[i].name = "otel_scope_version"; metric.label[i++].value = scope_version; }