Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ Increment the:
* [SDK] Implements options for the ParentBasedSampler with default values
[#3553](https://github.com/open-telemetry/opentelemetry-cpp/pull/3553)

* [SDK] View should not have a unit
[#3552](https://github.com/open-telemetry/opentelemetry-cpp/pull/3552)

Breaking changes:

* [SDK] View should not have a unit
[#3552](https://github.com/open-telemetry/opentelemetry-cpp/pull/3552)
* The `unit` parameter has been removed from the `View` constructor
and `ViewFactory::Create` methods.
* Please adjust SDK configuration code accordingly.

## [1.22 2025-07-11]

* [DOC] Udpate link to membership document
Expand Down
10 changes: 5 additions & 5 deletions examples/metrics_simple/metrics_ostream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void InitMetrics(const std::string &name)

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

auto sum_view = metrics_sdk::ViewFactory::Create(name, "description", unit,
metrics_sdk::AggregationType::kSum);
auto sum_view =
metrics_sdk::ViewFactory::Create(name, "description", metrics_sdk::AggregationType::kSum);

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

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

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

auto observable_sum_view = metrics_sdk::ViewFactory::Create(name, "test_description", unit,
auto observable_sum_view = metrics_sdk::ViewFactory::Create(name, "test_description",
metrics_sdk::AggregationType::kSum);

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

auto histogram_view = metrics_sdk::ViewFactory::Create(
name, "description", unit, metrics_sdk::AggregationType::kHistogram, aggregation_config);
name, "description", metrics_sdk::AggregationType::kHistogram, aggregation_config);

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

auto histogram_base2_view = metrics_sdk::ViewFactory::Create(
name, "description", unit, metrics_sdk::AggregationType::kBase2ExponentialHistogram,
name, "description", metrics_sdk::AggregationType::kBase2ExponentialHistogram,
base2_aggregation_config);

provider->AddView(std::move(histogram_base2_instrument_selector),
Expand Down
3 changes: 1 addition & 2 deletions examples/otlp/grpc_metric_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ void InitMetrics(std::string &name)
std::move(histogram_aggregation_config));

auto histogram_view = metric_sdk::ViewFactory::Create(
name, "des", unit, metric_sdk::AggregationType::kBase2ExponentialHistogram,
aggregation_config);
name, "des", metric_sdk::AggregationType::kBase2ExponentialHistogram, aggregation_config);

provider->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector),
std::move(histogram_view));
Expand Down
6 changes: 3 additions & 3 deletions examples/prometheus/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void InitMetrics(const std::string &name, const std::string &addr)

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

auto sum_view = metrics_sdk::ViewFactory::Create(counter_name, "description", counter_unit,
auto sum_view = metrics_sdk::ViewFactory::Create(counter_name, "description",
metrics_sdk::AggregationType::kSum);

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

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

auto histogram_view = metrics_sdk::ViewFactory::Create(
histogram_name, "description", histogram_unit, metrics_sdk::AggregationType::kHistogram);
auto histogram_view = metrics_sdk::ViewFactory::Create(histogram_name, "description",
metrics_sdk::AggregationType::kHistogram);

p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector),
std::move(histogram_view));
Expand Down
3 changes: 0 additions & 3 deletions sdk/include/opentelemetry/sdk/metrics/view/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ class View
public:
View(const std::string &name,
const std::string &description = "",
const std::string &unit = "",
AggregationType aggregation_type = AggregationType::kDefault,
std::shared_ptr<AggregationConfig> aggregation_config = nullptr,
std::unique_ptr<opentelemetry::sdk::metrics::AttributesProcessor> attributes_processor =
std::unique_ptr<opentelemetry::sdk::metrics::AttributesProcessor>(
new opentelemetry::sdk::metrics::DefaultAttributesProcessor()))
: name_(name),
description_(description),
unit_(unit),
aggregation_type_{aggregation_type},
aggregation_config_{aggregation_config},
attributes_processor_{std::move(attributes_processor)}
Expand Down Expand Up @@ -62,7 +60,6 @@ class View
private:
std::string name_;
std::string description_;
std::string unit_;
AggregationType aggregation_type_;
std::shared_ptr<AggregationConfig> aggregation_config_;
std::shared_ptr<AttributesProcessor> attributes_processor_;
Expand Down
7 changes: 0 additions & 7 deletions sdk/include/opentelemetry/sdk/metrics/view/view_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,15 @@ class OPENTELEMETRY_EXPORT ViewFactory

static std::unique_ptr<View> Create(const std::string &name,
const std::string &description,
const std::string &unit);

static std::unique_ptr<View> Create(const std::string &name,
const std::string &description,
const std::string &unit,
AggregationType aggregation_type);

static std::unique_ptr<View> Create(const std::string &name,
const std::string &description,
const std::string &unit,
AggregationType aggregation_type,
std::shared_ptr<AggregationConfig> aggregation_config);

static std::unique_ptr<View> Create(const std::string &name,
const std::string &description,
const std::string &unit,
AggregationType aggregation_type,
std::shared_ptr<AggregationConfig> aggregation_config,
std::unique_ptr<AttributesProcessor> attributes_processor);
Expand Down
18 changes: 4 additions & 14 deletions sdk/src/metrics/view/view_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,36 @@ std::unique_ptr<View> ViewFactory::Create(const std::string &name)

std::unique_ptr<View> ViewFactory::Create(const std::string &name, const std::string &description)
{
return Create(name, description, "", AggregationType::kDefault);
return Create(name, description, AggregationType::kDefault);
}

std::unique_ptr<View> ViewFactory::Create(const std::string &name,
const std::string &description,
const std::string &unit)
{
return Create(name, description, unit, AggregationType::kDefault);
}

std::unique_ptr<View> ViewFactory::Create(const std::string &name,
const std::string &description,
const std::string &unit,
AggregationType aggregation_type)
{
std::shared_ptr<AggregationConfig> aggregation_config(nullptr);
return Create(name, description, unit, aggregation_type, aggregation_config);
return Create(name, description, aggregation_type, aggregation_config);
}

std::unique_ptr<View> ViewFactory::Create(const std::string &name,
const std::string &description,
const std::string &unit,
AggregationType aggregation_type,
std::shared_ptr<AggregationConfig> aggregation_config)
{
auto attributes_processor =
std::unique_ptr<AttributesProcessor>(new DefaultAttributesProcessor());

return Create(name, description, unit, aggregation_type, std::move(aggregation_config),
return Create(name, description, aggregation_type, std::move(aggregation_config),
std::move(attributes_processor));
}

std::unique_ptr<View> ViewFactory::Create(const std::string &name,
const std::string &description,
const std::string &unit,
AggregationType aggregation_type,
std::shared_ptr<AggregationConfig> aggregation_config,
std::unique_ptr<AttributesProcessor> attributes_processor)
{
std::unique_ptr<View> view(new View(name, description, unit, aggregation_type,
std::unique_ptr<View> view(new View(name, description, aggregation_type,
std::move(aggregation_config),
std::move(attributes_processor)));
return view;
Expand Down
3 changes: 1 addition & 2 deletions sdk/test/metrics/histogram_aggregation_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ void RunBase2ExponentialHistogramAggregation(benchmark::State &state, int scale)
config.max_scale_ = scale;

std::unique_ptr<View> histogram_view{
new View("base2_expohisto", "description", instrument_unit,
AggregationType::kBase2ExponentialHistogram,
new View("base2_expohisto", "description", AggregationType::kBase2ExponentialHistogram,
std::make_shared<Base2ExponentialHistogramAggregationConfig>(config))};

std::unique_ptr<ViewRegistry> views{new ViewRegistry()};
Expand Down
3 changes: 1 addition & 2 deletions sdk/test/metrics/histogram_aggregation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ TEST(CounterToHistogram, Double)
std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
mp.AddMetricReader(reader);

std::unique_ptr<View> view{
new View("view1", "view1_description", "unit", AggregationType::kHistogram)};
std::unique_ptr<View> view{new View("view1", "view1_description", AggregationType::kHistogram)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kCounter, "counter1", "unit")};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down
8 changes: 4 additions & 4 deletions sdk/test/metrics/histogram_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ TEST(Histogram, DoubleCustomBuckets)
std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
config->boundaries_ = {10, 20, 30, 40};
std::unique_ptr<View> view{
new View("view1", "view1_description", instrument_unit, AggregationType::kHistogram, config)};
new View("view1", "view1_description", AggregationType::kHistogram, config)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down Expand Up @@ -163,7 +163,7 @@ TEST(Histogram, DoubleEmptyBuckets)
std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
config->boundaries_ = {};
std::unique_ptr<View> view{
new View("view1", "view1_description", instrument_unit, AggregationType::kHistogram, config)};
new View("view1", "view1_description", AggregationType::kHistogram, config)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down Expand Up @@ -278,7 +278,7 @@ TEST(Histogram, UInt64CustomBuckets)
std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
config->boundaries_ = {10, 20, 30, 40};
std::unique_ptr<View> view{
new View("view1", "view1_description", "ms", AggregationType::kHistogram, config)};
new View("view1", "view1_description", AggregationType::kHistogram, config)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down Expand Up @@ -338,7 +338,7 @@ TEST(Histogram, UInt64EmptyBuckets)
std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
config->boundaries_ = {};
std::unique_ptr<View> view{
new View("view1", "view1_description", "ms", AggregationType::kHistogram, config)};
new View("view1", "view1_description", AggregationType::kHistogram, config)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/metrics/meter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ TEST(MeterTest, RecordAfterProviderDestructionWithCustomProcessor_NoResetInMain)

// Register a View with custom processor
std::unique_ptr<View> view(
new View("my_counter", "", "", AggregationType::kSum, nullptr, std::move(processor)));
new View("my_counter", "", AggregationType::kSum, nullptr, std::move(processor)));
std::unique_ptr<InstrumentSelector> instr_selector(
new InstrumentSelector(InstrumentType::kCounter, "my_counter", ""));
std::unique_ptr<MeterSelector> meter_selector(new MeterSelector("test_meter", "", ""));
Expand Down
18 changes: 7 additions & 11 deletions sdk/test/metrics/sum_aggregation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ TEST(HistogramToSum, Double)
std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
mp.AddMetricReader(reader);

std::unique_ptr<View> view{
new View("view1", "view1_description", instrument_unit, AggregationType::kSum)};
std::unique_ptr<View> view{new View("view1", "view1_description", AggregationType::kSum)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down Expand Up @@ -109,9 +108,8 @@ TEST(HistogramToSumFilterAttributes, Double)
std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
mp.AddMetricReader(reader);

std::unique_ptr<View> view{new View("view1", "view1_description", instrument_unit,
AggregationType::kSum, dummy_aggregation_config,
std::move(attrproc))};
std::unique_ptr<View> view{new View("view1", "view1_description", AggregationType::kSum,
dummy_aggregation_config, std::move(attrproc))};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kHistogram, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down Expand Up @@ -153,7 +151,7 @@ TEST(CounterToSum, Double)
std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
mp.AddMetricReader(reader);

std::unique_ptr<View> view{new View("view1", "view1_description", "ms", AggregationType::kSum)};
std::unique_ptr<View> view{new View("view1", "view1_description", AggregationType::kSum)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kCounter, "counter1", "ms")};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down Expand Up @@ -212,9 +210,8 @@ TEST(CounterToSumFilterAttributes, Double)
std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
mp.AddMetricReader(reader);

std::unique_ptr<View> view{new View("view1", "view1_description", instrument_unit,
AggregationType::kSum, dummy_aggregation_config,
std::move(attrproc))};
std::unique_ptr<View> view{new View("view1", "view1_description", AggregationType::kSum,
dummy_aggregation_config, std::move(attrproc))};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kCounter, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
Expand Down Expand Up @@ -265,8 +262,7 @@ TEST_P(UpDownCounterToSumFixture, Double)

if (is_matching_view)
{
std::unique_ptr<View> view{
new View("view1", "view1_description", instrument_unit, AggregationType::kSum)};
std::unique_ptr<View> view{new View("view1", "view1_description", AggregationType::kSum)};
std::unique_ptr<InstrumentSelector> instrument_selector{
new InstrumentSelector(InstrumentType::kUpDownCounter, instrument_name, instrument_unit)};
std::unique_ptr<MeterSelector> meter_selector{
Expand Down
Loading