Skip to content

Commit ac1172e

Browse files
authored
[SDK] View should not have a unit (#3552)
1 parent 03e0452 commit ac1172e

File tree

12 files changed

+38
-54
lines changed

12 files changed

+38
-54
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ Increment the:
2727
* [SDK] Implements options for the ParentBasedSampler with default values
2828
[#3553](https://github.com/open-telemetry/opentelemetry-cpp/pull/3553)
2929

30+
* [SDK] View should not have a unit
31+
[#3552](https://github.com/open-telemetry/opentelemetry-cpp/pull/3552)
32+
33+
Breaking changes:
34+
35+
* [SDK] View should not have a unit
36+
[#3552](https://github.com/open-telemetry/opentelemetry-cpp/pull/3552)
37+
* The `unit` parameter has been removed from the `View` constructor
38+
and `ViewFactory::Create` methods.
39+
* Please adjust SDK configuration code accordingly.
40+
3041
## [1.22 2025-07-11]
3142

3243
* [DOC] Udpate link to membership document

examples/metrics_simple/metrics_ostream.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ void InitMetrics(const std::string &name)
7171

7272
auto meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema);
7373

74-
auto sum_view = metrics_sdk::ViewFactory::Create(name, "description", unit,
75-
metrics_sdk::AggregationType::kSum);
74+
auto sum_view =
75+
metrics_sdk::ViewFactory::Create(name, "description", metrics_sdk::AggregationType::kSum);
7676

7777
provider->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view));
7878

@@ -84,7 +84,7 @@ void InitMetrics(const std::string &name)
8484

8585
auto observable_meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema);
8686

87-
auto observable_sum_view = metrics_sdk::ViewFactory::Create(name, "test_description", unit,
87+
auto observable_sum_view = metrics_sdk::ViewFactory::Create(name, "test_description",
8888
metrics_sdk::AggregationType::kSum);
8989

9090
provider->AddView(std::move(observable_instrument_selector), std::move(observable_meter_selector),
@@ -109,7 +109,7 @@ void InitMetrics(const std::string &name)
109109
std::move(histogram_aggregation_config));
110110

111111
auto histogram_view = metrics_sdk::ViewFactory::Create(
112-
name, "description", unit, metrics_sdk::AggregationType::kHistogram, aggregation_config);
112+
name, "description", metrics_sdk::AggregationType::kHistogram, aggregation_config);
113113

114114
provider->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector),
115115
std::move(histogram_view));
@@ -132,7 +132,7 @@ void InitMetrics(const std::string &name)
132132
std::move(histogram_base2_aggregation_config));
133133

134134
auto histogram_base2_view = metrics_sdk::ViewFactory::Create(
135-
name, "description", unit, metrics_sdk::AggregationType::kBase2ExponentialHistogram,
135+
name, "description", metrics_sdk::AggregationType::kBase2ExponentialHistogram,
136136
base2_aggregation_config);
137137

138138
provider->AddView(std::move(histogram_base2_instrument_selector),

examples/otlp/grpc_metric_main.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ void InitMetrics(std::string &name)
8383
std::move(histogram_aggregation_config));
8484

8585
auto histogram_view = metric_sdk::ViewFactory::Create(
86-
name, "des", unit, metric_sdk::AggregationType::kBase2ExponentialHistogram,
87-
aggregation_config);
86+
name, "des", metric_sdk::AggregationType::kBase2ExponentialHistogram, aggregation_config);
8887

8988
provider->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector),
9089
std::move(histogram_view));

examples/prometheus/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void InitMetrics(const std::string &name, const std::string &addr)
6666

6767
auto meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema);
6868

69-
auto sum_view = metrics_sdk::ViewFactory::Create(counter_name, "description", counter_unit,
69+
auto sum_view = metrics_sdk::ViewFactory::Create(counter_name, "description",
7070
metrics_sdk::AggregationType::kSum);
7171

7272
p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view));
@@ -80,8 +80,8 @@ void InitMetrics(const std::string &name, const std::string &addr)
8080

8181
auto histogram_meter_selector = metrics_sdk::MeterSelectorFactory::Create(name, version, schema);
8282

83-
auto histogram_view = metrics_sdk::ViewFactory::Create(
84-
histogram_name, "description", histogram_unit, metrics_sdk::AggregationType::kHistogram);
83+
auto histogram_view = metrics_sdk::ViewFactory::Create(histogram_name, "description",
84+
metrics_sdk::AggregationType::kHistogram);
8585

8686
p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector),
8787
std::move(histogram_view));

sdk/include/opentelemetry/sdk/metrics/view/view.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ class View
2626
public:
2727
View(const std::string &name,
2828
const std::string &description = "",
29-
const std::string &unit = "",
3029
AggregationType aggregation_type = AggregationType::kDefault,
3130
std::shared_ptr<AggregationConfig> aggregation_config = nullptr,
3231
std::unique_ptr<opentelemetry::sdk::metrics::AttributesProcessor> attributes_processor =
3332
std::unique_ptr<opentelemetry::sdk::metrics::AttributesProcessor>(
3433
new opentelemetry::sdk::metrics::DefaultAttributesProcessor()))
3534
: name_(name),
3635
description_(description),
37-
unit_(unit),
3836
aggregation_type_{aggregation_type},
3937
aggregation_config_{aggregation_config},
4038
attributes_processor_{std::move(attributes_processor)}
@@ -62,7 +60,6 @@ class View
6260
private:
6361
std::string name_;
6462
std::string description_;
65-
std::string unit_;
6663
AggregationType aggregation_type_;
6764
std::shared_ptr<AggregationConfig> aggregation_config_;
6865
std::shared_ptr<AttributesProcessor> attributes_processor_;

sdk/include/opentelemetry/sdk/metrics/view/view_factory.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,15 @@ class OPENTELEMETRY_EXPORT ViewFactory
3030

3131
static std::unique_ptr<View> Create(const std::string &name,
3232
const std::string &description,
33-
const std::string &unit);
34-
35-
static std::unique_ptr<View> Create(const std::string &name,
36-
const std::string &description,
37-
const std::string &unit,
3833
AggregationType aggregation_type);
3934

4035
static std::unique_ptr<View> Create(const std::string &name,
4136
const std::string &description,
42-
const std::string &unit,
4337
AggregationType aggregation_type,
4438
std::shared_ptr<AggregationConfig> aggregation_config);
4539

4640
static std::unique_ptr<View> Create(const std::string &name,
4741
const std::string &description,
48-
const std::string &unit,
4942
AggregationType aggregation_type,
5043
std::shared_ptr<AggregationConfig> aggregation_config,
5144
std::unique_ptr<AttributesProcessor> attributes_processor);

sdk/src/metrics/view/view_factory.cc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,36 @@ std::unique_ptr<View> ViewFactory::Create(const std::string &name)
2525

2626
std::unique_ptr<View> ViewFactory::Create(const std::string &name, const std::string &description)
2727
{
28-
return Create(name, description, "", AggregationType::kDefault);
28+
return Create(name, description, AggregationType::kDefault);
2929
}
3030

3131
std::unique_ptr<View> ViewFactory::Create(const std::string &name,
3232
const std::string &description,
33-
const std::string &unit)
34-
{
35-
return Create(name, description, unit, AggregationType::kDefault);
36-
}
37-
38-
std::unique_ptr<View> ViewFactory::Create(const std::string &name,
39-
const std::string &description,
40-
const std::string &unit,
4133
AggregationType aggregation_type)
4234
{
4335
std::shared_ptr<AggregationConfig> aggregation_config(nullptr);
44-
return Create(name, description, unit, aggregation_type, aggregation_config);
36+
return Create(name, description, aggregation_type, aggregation_config);
4537
}
4638

4739
std::unique_ptr<View> ViewFactory::Create(const std::string &name,
4840
const std::string &description,
49-
const std::string &unit,
5041
AggregationType aggregation_type,
5142
std::shared_ptr<AggregationConfig> aggregation_config)
5243
{
5344
auto attributes_processor =
5445
std::unique_ptr<AttributesProcessor>(new DefaultAttributesProcessor());
5546

56-
return Create(name, description, unit, aggregation_type, std::move(aggregation_config),
47+
return Create(name, description, aggregation_type, std::move(aggregation_config),
5748
std::move(attributes_processor));
5849
}
5950

6051
std::unique_ptr<View> ViewFactory::Create(const std::string &name,
6152
const std::string &description,
62-
const std::string &unit,
6353
AggregationType aggregation_type,
6454
std::shared_ptr<AggregationConfig> aggregation_config,
6555
std::unique_ptr<AttributesProcessor> attributes_processor)
6656
{
67-
std::unique_ptr<View> view(new View(name, description, unit, aggregation_type,
57+
std::unique_ptr<View> view(new View(name, description, aggregation_type,
6858
std::move(aggregation_config),
6959
std::move(attributes_processor)));
7060
return view;

sdk/test/metrics/histogram_aggregation_benchmark.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ void RunBase2ExponentialHistogramAggregation(benchmark::State &state, int scale)
116116
config.max_scale_ = scale;
117117

118118
std::unique_ptr<View> histogram_view{
119-
new View("base2_expohisto", "description", instrument_unit,
120-
AggregationType::kBase2ExponentialHistogram,
119+
new View("base2_expohisto", "description", AggregationType::kBase2ExponentialHistogram,
121120
std::make_shared<Base2ExponentialHistogramAggregationConfig>(config))};
122121

123122
std::unique_ptr<ViewRegistry> views{new ViewRegistry()};

sdk/test/metrics/histogram_aggregation_test.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ TEST(CounterToHistogram, Double)
8787
std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
8888
mp.AddMetricReader(reader);
8989

90-
std::unique_ptr<View> view{
91-
new View("view1", "view1_description", "unit", AggregationType::kHistogram)};
90+
std::unique_ptr<View> view{new View("view1", "view1_description", AggregationType::kHistogram)};
9291
std::unique_ptr<InstrumentSelector> instrument_selector{
9392
new InstrumentSelector(InstrumentType::kCounter, "counter1", "unit")};
9493
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};

sdk/test/metrics/histogram_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ TEST(Histogram, DoubleCustomBuckets)
103103
std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
104104
config->boundaries_ = {10, 20, 30, 40};
105105
std::unique_ptr<View> view{
106-
new View("view1", "view1_description", instrument_unit, AggregationType::kHistogram, config)};
106+
new View("view1", "view1_description", AggregationType::kHistogram, config)};
107107
std::unique_ptr<InstrumentSelector> instrument_selector{
108108
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
109109
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
@@ -163,7 +163,7 @@ TEST(Histogram, DoubleEmptyBuckets)
163163
std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
164164
config->boundaries_ = {};
165165
std::unique_ptr<View> view{
166-
new View("view1", "view1_description", instrument_unit, AggregationType::kHistogram, config)};
166+
new View("view1", "view1_description", AggregationType::kHistogram, config)};
167167
std::unique_ptr<InstrumentSelector> instrument_selector{
168168
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
169169
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
@@ -278,7 +278,7 @@ TEST(Histogram, UInt64CustomBuckets)
278278
std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
279279
config->boundaries_ = {10, 20, 30, 40};
280280
std::unique_ptr<View> view{
281-
new View("view1", "view1_description", "ms", AggregationType::kHistogram, config)};
281+
new View("view1", "view1_description", AggregationType::kHistogram, config)};
282282
std::unique_ptr<InstrumentSelector> instrument_selector{
283283
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
284284
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
@@ -338,7 +338,7 @@ TEST(Histogram, UInt64EmptyBuckets)
338338
std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
339339
config->boundaries_ = {};
340340
std::unique_ptr<View> view{
341-
new View("view1", "view1_description", "ms", AggregationType::kHistogram, config)};
341+
new View("view1", "view1_description", AggregationType::kHistogram, config)};
342342
std::unique_ptr<InstrumentSelector> instrument_selector{
343343
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
344344
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};

0 commit comments

Comments
 (0)