Skip to content

Commit cb71fc2

Browse files
committed
Address review comment: exclude scope labels from target_info
1 parent 2a6f489 commit cb71fc2

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎exporters/prometheus/src/exporter_utils.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ prometheus_client::MetricType PrometheusExporterUtils::TranslateType(
689689

690690
void PrometheusExporterUtils::SetTarget(
691691
const sdk::metrics::ResourceMetrics &data,
692-
const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope,
692+
const opentelemetry::sdk::instrumentationscope::InstrumentationScope * /* scope */,
693693
std::vector<::prometheus::MetricFamily> *output)
694694
{
695695
if (output == nullptr || data.resource_ == nullptr)
@@ -707,7 +707,7 @@ void PrometheusExporterUtils::SetTarget(
707707
metric.info.value = 1.0;
708708

709709
metric_sdk::PointAttributes empty_attributes;
710-
SetMetricBasic(metric, empty_attributes, scope, data.resource_);
710+
SetMetricBasic(metric, empty_attributes, nullptr, data.resource_);
711711

712712
for (auto &label : data.resource_->GetAttributes())
713713
{

‎exporters/prometheus/test/exporter_utils_test.cc‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,4 +777,45 @@ TEST(PrometheusExporterUtils, InstrumentationScopePointAttributeCollisions)
777777
}
778778
}
779779

780+
TEST(PrometheusExporterUtils, TargetInfoExcludesInstrumentationScopeLabels)
781+
{
782+
auto scope = InstrumentationScope::Create(
783+
"library_name", "1.2.0", "https://opentelemetry.io/schemas/1.21.0", {{"foo", "scope_foo"}});
784+
785+
metric_sdk::SumPointData sum_point_data{};
786+
sum_point_data.value_ = 5.0;
787+
metric_sdk::MetricData metric_data{
788+
metric_sdk::InstrumentDescriptor{"requests", "description", "1",
789+
metric_sdk::InstrumentType::kCounter,
790+
metric_sdk::InstrumentValueType::kDouble},
791+
metric_sdk::AggregationTemporality::kCumulative, opentelemetry::common::SystemTimestamp{},
792+
opentelemetry::common::SystemTimestamp{},
793+
std::vector<metric_sdk::PointDataAttributes>{{{}, sum_point_data}}};
794+
795+
Resource resource = Resource::Create(
796+
ResourceAttributes{{"service.name", "test_service"}, {"otel_scope_foo", "resource_foo"}});
797+
metric_sdk::ResourceMetrics data{
798+
&resource, std::vector<metric_sdk::ScopeMetrics>{
799+
{scope.get(), std::vector<metric_sdk::MetricData>{metric_data}}}};
800+
801+
auto translated = PrometheusExporterUtils::TranslateToPrometheus(data, true, false);
802+
ASSERT_EQ(translated.size(), 2U);
803+
ASSERT_EQ(translated[0].name, "target");
804+
ASSERT_EQ(translated[0].metric.size(), 1U);
805+
806+
std::size_t otel_scope_foo_count = 0;
807+
for (const auto &label : translated[0].metric[0].label)
808+
{
809+
EXPECT_NE(label.name, "otel_scope_name");
810+
EXPECT_NE(label.name, "otel_scope_version");
811+
EXPECT_NE(label.name, "otel_scope_schema_url");
812+
if (label.name == "otel_scope_foo")
813+
{
814+
EXPECT_EQ(label.value, "resource_foo");
815+
++otel_scope_foo_count;
816+
}
817+
}
818+
EXPECT_EQ(otel_scope_foo_count, 1U);
819+
}
820+
780821
OPENTELEMETRY_END_NAMESPACE

0 commit comments

Comments
 (0)