Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] MeterProvider should own MeterContext, not share it #2218

Merged
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ Increment the:
* [API] Remove include_trace_context
[#2194](https://github.com/open-telemetry/opentelemetry-cpp/pull/2194)

* [SDK] MeterProvider should own MeterContext, not share it
[#2218](https://github.com/open-telemetry/opentelemetry-cpp/pull/2218)

Important changes:

* [REMOVAL] Remove the jaeger exporter
[#2031](https://github.com/open-telemetry/opentelemetry-cpp/pull/2031)
* The CMake `WITH_JAEGER` option has been removed
* Please remove usage of `WITH_JAEGER` from user scripts and makefiles.

* [SDK] MeterProvider should own MeterContext, not share it
[#2218](https://github.com/open-telemetry/opentelemetry-cpp/pull/2218)
* The `MeterProvider` constructor now takes a `unique_ptr` on
`MeterContext`, instead of a `shared_ptr`.
* Please adjust SDK configuration code accordingly.

## [1.9.1] 2023-05-26

* [DEPRECATION] Drop C++11 support
Expand Down
4 changes: 1 addition & 3 deletions examples/otlp/grpc_metric_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ void InitMetrics()
auto context = metric_sdk::MeterContextFactory::Create();
context->AddMetricReader(std::move(reader));

std::shared_ptr<metric_sdk::MeterContext> s_context(std::move(context));

auto u_provider = metric_sdk::MeterProviderFactory::Create(s_context);
auto u_provider = metric_sdk::MeterProviderFactory::Create(std::move(context));
std::shared_ptr<opentelemetry::metrics::MeterProvider> provider(std::move(u_provider));

metrics_api::Provider::SetMeterProvider(provider);
Expand Down
4 changes: 1 addition & 3 deletions examples/otlp/http_metric_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ void InitMetrics()
auto context = metric_sdk::MeterContextFactory::Create();
context->AddMetricReader(std::move(reader));

std::shared_ptr<metric_sdk::MeterContext> s_context(std::move(context));

auto u_provider = metric_sdk::MeterProviderFactory::Create(s_context);
auto u_provider = metric_sdk::MeterProviderFactory::Create(std::move(context));
std::shared_ptr<opentelemetry::metrics::MeterProvider> provider(std::move(u_provider));

metrics_api::Provider::SetMeterProvider(provider);
Expand Down
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/metrics/meter_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class MeterProvider final : public opentelemetry::metrics::MeterProvider

/**
* Initialize a new meter provider with a specified context
* @param context The shared meter configuration/pipeline for this provider.
* @param context The owned meter configuration/pipeline for this provider.
*/
explicit MeterProvider(std::shared_ptr<MeterContext> context) noexcept;
explicit MeterProvider(std::unique_ptr<MeterContext> context) noexcept;

nostd::shared_ptr<opentelemetry::metrics::Meter> GetMeter(
nostd::string_view name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MeterProviderFactory
const opentelemetry::sdk::resource::Resource &resource);

static std::unique_ptr<opentelemetry::metrics::MeterProvider> Create(
std::shared_ptr<sdk::metrics::MeterContext> context);
std::unique_ptr<sdk::metrics::MeterContext> context);
};

} // namespace metrics
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/metrics/meter_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ namespace metrics
namespace resource = opentelemetry::sdk::resource;
namespace metrics_api = opentelemetry::metrics;

MeterProvider::MeterProvider(std::shared_ptr<MeterContext> context) noexcept : context_{context} {}
MeterProvider::MeterProvider(std::unique_ptr<MeterContext> context) noexcept
: context_(std::move(context))
{}

MeterProvider::MeterProvider(std::unique_ptr<ViewRegistry> views,
sdk::resource::Resource resource) noexcept
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/metrics/meter_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::unique_ptr<opentelemetry::metrics::MeterProvider> MeterProviderFactory::Cre
}

std::unique_ptr<opentelemetry::metrics::MeterProvider> MeterProviderFactory::Create(
std::shared_ptr<sdk::metrics::MeterContext> context)
std::unique_ptr<sdk::metrics::MeterContext> context)
{
std::unique_ptr<opentelemetry::metrics::MeterProvider> provider(
new metrics_sdk::MeterProvider(std::move(context)));
Expand Down