Skip to content

Commit f61493d

Browse files
authored
Merge branch 'main' into add-link-to-dependency-versions
2 parents c136f88 + ba38077 commit f61493d

File tree

14 files changed

+65
-58
lines changed

14 files changed

+65
-58
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));

ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class HttpOperation
338338
std::promise<CURLcode> result_promise;
339339
std::future<CURLcode> result_future;
340340
};
341+
friend class HttpOperationAccessor;
341342
std::unique_ptr<AsyncData> async_data_;
342343
};
343344
} // namespace curl

ext/src/http/client/curl/http_operation_curl.cc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ namespace client
4747
namespace curl
4848
{
4949

50+
class HttpOperationAccessor
51+
{
52+
public:
53+
OPENTELEMETRY_SANITIZER_NO_THREAD static std::thread::id GetThreadId(
54+
const HttpOperation::AsyncData &async_data)
55+
{
56+
#if !(defined(OPENTELEMETRY_HAVE_THREAD_SANITIZER) && OPENTELEMETRY_HAVE_THREAD_SANITIZER)
57+
std::atomic_thread_fence(std::memory_order_acquire);
58+
#endif
59+
return async_data.callback_thread;
60+
}
61+
62+
OPENTELEMETRY_SANITIZER_NO_THREAD static void SetThreadId(HttpOperation::AsyncData &async_data,
63+
std::thread::id thread_id)
64+
{
65+
async_data.callback_thread = thread_id;
66+
#if !(defined(OPENTELEMETRY_HAVE_THREAD_SANITIZER) && OPENTELEMETRY_HAVE_THREAD_SANITIZER)
67+
std::atomic_thread_fence(std::memory_order_release);
68+
#endif
69+
}
70+
};
71+
5072
size_t HttpOperation::WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
5173
{
5274
HttpOperation *self = reinterpret_cast<HttpOperation *>(userp);
@@ -335,7 +357,7 @@ HttpOperation::~HttpOperation()
335357
case opentelemetry::ext::http::client::SessionState::Sending: {
336358
if (async_data_ && async_data_->result_future.valid())
337359
{
338-
if (async_data_->callback_thread != std::this_thread::get_id())
360+
if (HttpOperationAccessor::GetThreadId(*async_data_) != std::this_thread::get_id())
339361
{
340362
async_data_->result_future.wait();
341363
last_curl_result_ = async_data_->result_future.get();
@@ -360,7 +382,7 @@ void HttpOperation::Finish()
360382
if (async_data_ && async_data_->result_future.valid())
361383
{
362384
// We should not wait in callback from Cleanup()
363-
if (async_data_->callback_thread != std::this_thread::get_id())
385+
if (HttpOperationAccessor::GetThreadId(*async_data_) != std::this_thread::get_id())
364386
{
365387
async_data_->result_future.wait();
366388
last_curl_result_ = async_data_->result_future.get();
@@ -412,9 +434,9 @@ void HttpOperation::Cleanup()
412434
callback.swap(async_data_->callback);
413435
if (callback)
414436
{
415-
async_data_->callback_thread = std::this_thread::get_id();
437+
HttpOperationAccessor::SetThreadId(*async_data_, std::this_thread::get_id());
416438
callback(*this);
417-
async_data_->callback_thread = std::thread::id();
439+
HttpOperationAccessor::SetThreadId(*async_data_, std::thread::id());
418440
}
419441

420442
// Set value to promise to continue Finish()

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()};

0 commit comments

Comments
 (0)