From b6ca2f2b22c36e0fbd437c7b3d596cffad2286bf Mon Sep 17 00:00:00 2001 From: owent Date: Tue, 3 Oct 2023 23:02:02 +0800 Subject: [PATCH] Add scope for target-info Signed-off-by: owent --- .../exporters/prometheus/exporter_utils.h | 1 + exporters/prometheus/src/exporter_utils.cc | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index c0cb85c62f..96c7ac8826 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -58,6 +58,7 @@ class PrometheusExporterUtils * Add a target_info metric to collect resource attributes */ static void SetTarget(const sdk::metrics::ResourceMetrics &data, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, std::vector<::prometheus::MetricFamily> *output); /** diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 0ecabc3983..49ece800a5 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -134,9 +134,9 @@ std::vector PrometheusExporterUtils::TranslateT output.reserve(reserve_size); // Append target_info as the first metric - if (populate_target_info) + if (populate_target_info && !data.scope_metric_data_.empty()) { - SetTarget(data, &output); + SetTarget(data, (*data.scope_metric_data_.begin()).scope_, &output); } for (const auto &instrumentation_info : data.scope_metric_data_) @@ -293,8 +293,10 @@ prometheus_client::MetricType PrometheusExporterUtils::TranslateType( } } -void PrometheusExporterUtils::SetTarget(const sdk::metrics::ResourceMetrics &data, - std::vector<::prometheus::MetricFamily> *output) +void PrometheusExporterUtils::SetTarget( + const sdk::metrics::ResourceMetrics &data, + const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope, + std::vector<::prometheus::MetricFamily> *output) { if (output == nullptr || data.resource_ == nullptr) { @@ -311,7 +313,7 @@ void PrometheusExporterUtils::SetTarget(const sdk::metrics::ResourceMetrics &dat metric.info.value = 1.0; metric_sdk::PointAttributes empty_attributes; - SetMetricBasic(metric, empty_attributes, data.resource_); + SetMetricBasic(metric, empty_attributes, scope, data.resource_); for (auto &label : data.resource_->GetAttributes()) {