Skip to content

Commit f084fbc

Browse files
authored
[EXPORTER] Rename populate_otel_scope to without_otel_scope (open-telemetry#2479)
1 parent 928a87c commit f084fbc

File tree

8 files changed

+17
-18
lines changed

8 files changed

+17
-18
lines changed

exporters/prometheus/include/opentelemetry/exporters/prometheus/collector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PrometheusCollector : public prometheus_client::Collectable
3333
*/
3434
explicit PrometheusCollector(sdk::metrics::MetricReader *reader,
3535
bool populate_target_info,
36-
bool populate_otel_scope);
36+
bool without_otel_scope);
3737

3838
/**
3939
* Collects all metrics data from metricsToCollect collection.
@@ -45,7 +45,7 @@ class PrometheusCollector : public prometheus_client::Collectable
4545
private:
4646
sdk::metrics::MetricReader *reader_;
4747
bool populate_target_info_;
48-
bool populate_otel_scope_;
48+
bool without_otel_scope_;
4949

5050
/*
5151
* Lock when operating the metricsToCollect collection

exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct PrometheusExporterOptions
2727
bool populate_target_info = true;
2828

2929
// Populating otel_scope_name/otel_scope_labels attributes
30-
bool populate_otel_scope = true;
30+
bool without_otel_scope = false;
3131
};
3232

3333
} // namespace metrics

exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ class PrometheusExporterUtils
2828
*
2929
* @param records a collection of metrics in OpenTelemetry
3030
* @param populate_target_info whether to populate target_info
31-
* @param populate_otel_scope whether to populate otel_scope_name and otel_scope_version
31+
* @param without_otel_scope whether to populate otel_scope_name and otel_scope_version
3232
* attributes
3333
* @return a collection of translated metrics that is acceptable by Prometheus
3434
*/
3535
static std::vector<::prometheus::MetricFamily> TranslateToPrometheus(
3636
const sdk::metrics::ResourceMetrics &data,
3737
bool populate_target_info = true,
38-
bool populate_otel_scope = true);
38+
bool without_otel_scope = false);
3939

4040
private:
4141
/**

exporters/prometheus/src/collector.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace metrics
1919
*/
2020
PrometheusCollector::PrometheusCollector(sdk::metrics::MetricReader *reader,
2121
bool populate_target_info,
22-
bool populate_otel_scope)
22+
bool without_otel_scope)
2323
: reader_(reader),
2424
populate_target_info_(populate_target_info),
25-
populate_otel_scope_(populate_otel_scope)
25+
without_otel_scope_(without_otel_scope)
2626
{}
2727

2828
/**
@@ -45,7 +45,7 @@ std::vector<prometheus_client::MetricFamily> PrometheusCollector::Collect() cons
4545

4646
reader_->Collect([&result, this](sdk::metrics::ResourceMetrics &metric_data) {
4747
auto prometheus_metric_data = PrometheusExporterUtils::TranslateToPrometheus(
48-
metric_data, this->populate_target_info_, this->populate_otel_scope_);
48+
metric_data, this->populate_target_info_, this->without_otel_scope_);
4949
for (auto &data : prometheus_metric_data)
5050
result.emplace_back(data);
5151
return true;

exporters/prometheus/src/exporter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PrometheusExporter::PrometheusExporter(const PrometheusExporterOptions &options)
3131
return;
3232
}
3333
collector_ = std::shared_ptr<PrometheusCollector>(
34-
new PrometheusCollector(this, options_.populate_target_info, options_.populate_otel_scope));
34+
new PrometheusCollector(this, options_.populate_target_info, options_.without_otel_scope));
3535

3636
exposer_->RegisterCollectable(collector_);
3737
}

exporters/prometheus/src/exporter_options.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ inline const std::string GetPrometheusDefaultHttpEndpoint()
2525
return exists ? endpoint : kPrometheusEndpointDefault;
2626
}
2727

28-
inline bool GetPrometheusPopulateOtelScope()
28+
inline bool GetPrometheusWithoutOtelScope()
2929
{
30-
constexpr char kPrometheusPopulateOtelScope[] =
31-
"OTEL_CPP_PROMETHEUS_EXPORTER_POPULATE_OTEL_SCOPE";
30+
constexpr char kPrometheusWithoutOtelScope[] = "OTEL_CPP_PROMETHEUS_EXPORTER_WITHOUT_OTEL_SCOPE";
3231

3332
bool setting;
3433
auto exists =
35-
opentelemetry::sdk::common::GetBoolEnvironmentVariable(kPrometheusPopulateOtelScope, setting);
34+
opentelemetry::sdk::common::GetBoolEnvironmentVariable(kPrometheusWithoutOtelScope, setting);
3635

3736
return exists ? setting : true;
3837
}
@@ -52,7 +51,7 @@ inline bool GetPrometheusPopulateTargetInfo()
5251
PrometheusExporterOptions::PrometheusExporterOptions()
5352
: url(GetPrometheusDefaultHttpEndpoint()),
5453
populate_target_info(GetPrometheusPopulateTargetInfo()),
55-
populate_otel_scope(GetPrometheusPopulateOtelScope())
54+
without_otel_scope(GetPrometheusWithoutOtelScope())
5655
{}
5756

5857
} // namespace metrics

exporters/prometheus/src/exporter_utils.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ std::string SanitizeLabel(std::string label_key)
108108
std::vector<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateToPrometheus(
109109
const sdk::metrics::ResourceMetrics &data,
110110
bool populate_target_info,
111-
bool populate_otel_scope)
111+
bool without_otel_scope)
112112
{
113113

114114
// initialize output vector
@@ -129,7 +129,7 @@ std::vector<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateT
129129
{
130130
SetTarget(data,
131131
data.scope_metric_data_.begin()->metric_data_.begin()->end_ts.time_since_epoch(),
132-
populate_otel_scope ? (*data.scope_metric_data_.begin()).scope_ : nullptr, &output);
132+
without_otel_scope ? nullptr : (*data.scope_metric_data_.begin()).scope_, &output);
133133
}
134134

135135
for (const auto &instrumentation_info : data.scope_metric_data_)
@@ -153,7 +153,7 @@ std::vector<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateT
153153
metric_data.instrument_descriptor.unit_, type);
154154
metric_family.type = type;
155155
const opentelemetry::sdk::instrumentationscope::InstrumentationScope *scope =
156-
populate_otel_scope ? instrumentation_info.scope_ : nullptr;
156+
without_otel_scope ? nullptr : instrumentation_info.scope_;
157157

158158
for (const auto &point_data_attr : metric_data.point_data_attr_)
159159
{

exporters/prometheus/test/collector_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ TEST(PrometheusCollector, BasicTests)
7373
MockMetricReader *reader = new MockMetricReader();
7474
MockMetricProducer *producer = new MockMetricProducer();
7575
reader->SetMetricProducer(producer);
76-
PrometheusCollector collector(reader, true, true);
76+
PrometheusCollector collector(reader, true, false);
7777
auto data = collector.Collect();
7878

7979
// Collection size should be the same as the size

0 commit comments

Comments
 (0)