Skip to content

Commit

Permalink
Add scope for target-info
Browse files Browse the repository at this point in the history
Signed-off-by: owent <[email protected]>
  • Loading branch information
owent committed Oct 3, 2023
1 parent dd737e3 commit b6ca2f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
12 changes: 7 additions & 5 deletions exporters/prometheus/src/exporter_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ std::vector<prometheus_client::MetricFamily> 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_)
Expand Down Expand Up @@ -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)
{
Expand All @@ -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())
{
Expand Down

0 comments on commit b6ca2f2

Please sign in to comment.