Skip to content

Commit

Permalink
[SDK] MeterProvider should own MeterContext, not share it (open-telem…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Jul 6, 2023
1 parent 5466c5b commit 6ecd201
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
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

0 comments on commit 6ecd201

Please sign in to comment.