Skip to content

Commit

Permalink
Merge branch 'main' into fix_remove_meter_2184
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff committed Jul 10, 2023
2 parents 819d3cf + 8b61318 commit f7c5320
Show file tree
Hide file tree
Showing 29 changed files with 120 additions and 66 deletions.
32 changes: 27 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,41 @@ Increment the:
* [API] Remove Meters
[#2205](https://github.com/open-telemetry/opentelemetry-cpp/pull/2205)

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

* [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] TracerProvider should own TracerContext, not share it
[#2221](https://github.com/open-telemetry/opentelemetry-cpp/pull/2221)

Important changes:

* [API] Remove Meters
[#2205](https://github.com/open-telemetry/opentelemetry-cpp/pull/2205)
* The CMake option `WITH_REMOVE_METER_PREVIEW` was added.
* This option is experimental, and may change in the future.
* Enabling it is an ABI breaking change.

Breaking 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.

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

## [1.9.1] 2023-05-26

* [DEPRECATION] Drop C++11 support
Expand Down
1 change: 1 addition & 0 deletions api/include/opentelemetry/logs/severity.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once
#ifdef ENABLE_LOGS_PREVIEW

# include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
Expand Down
6 changes: 3 additions & 3 deletions bazel/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def opentelemetry_cpp_deps():
http_archive,
name = "com_github_opentelemetry_proto",
build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD",
sha256 = "6ab267cf82832ed60ad075d574c78da736193eecb9693e8a8d02f65d6d3f3520",
strip_prefix = "opentelemetry-proto-0.20.0",
sha256 = "a13a1a7b76a1f22a0ca2e6c293e176ffef031413ab8ba653a82a1dbc286a3a33",
strip_prefix = "opentelemetry-proto-1.0.0",
urls = [
"https://github.com/open-telemetry/opentelemetry-proto/archive/v0.20.0.tar.gz",
"https://github.com/open-telemetry/opentelemetry-proto/archive/v1.0.0.tar.gz",
],
)

Expand Down
22 changes: 18 additions & 4 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ mkdir -p "${BUILD_DIR}"
[ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin
mkdir -p "${PLUGIN_DIR}"

IWYU=""
MAKE_COMMAND="make -k -j \$(nproc)"
if [[ "${CXX}" == *clang* ]]; then
MAKE_COMMAND="make -k CXX=include-what-you-use CXXFLAGS=\"-Xiwyu --error_always\" -j \$(nproc)"
IWYU="-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=iwyu"
fi

echo "make command: ${MAKE_COMMAND}"
echo "IWYU option: ${IWYU}"

BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW"
BAZEL_OPTIONS="--cxxopt=-std=c++14 $BAZEL_OPTIONS_DEFAULT"

Expand Down Expand Up @@ -107,8 +117,9 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
-DWITH_ASYNC_EXPORT_PREVIEW=OFF \
-DOTELCPP_MAINTAINER_MODE=ON \
-DWITH_NO_DEPRECATED_CODE=ON \
${IWYU} \
"${SRC_DIR}"
make -k
eval "$MAKE_COMMAND"
make test
exit 0
elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
Expand All @@ -129,8 +140,9 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DOTELCPP_MAINTAINER_MODE=ON \
-DWITH_NO_DEPRECATED_CODE=ON \
${IWYU} \
"${SRC_DIR}"
make -k -j $(nproc)
eval "$MAKE_COMMAND"
make test
exit 0
elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then
Expand Down Expand Up @@ -201,8 +213,9 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DCMAKE_CXX_STANDARD=20 \
${IWYU} \
"${SRC_DIR}"
make -j $(nproc)
eval "$MAKE_COMMAND"
make test
exit 0
elif [[ "$1" == "cmake.c++20.stl.test" ]]; then
Expand All @@ -214,8 +227,9 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_STL=ON \
${IWYU} \
"${SRC_DIR}"
make -j $(nproc)
eval "$MAKE_COMMAND"
make test
exit 0
elif [[ "$1" == "cmake.legacy.test" ]]; then
Expand Down
3 changes: 2 additions & 1 deletion ci/setup_ci_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ apt-get install --no-install-recommends --no-install-suggests -y \
wget \
git \
valgrind \
lcov
lcov \
iwyu
9 changes: 9 additions & 0 deletions cmake/opentelemetry-cpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,12 @@ find_package_handle_standard_args(
${CMAKE_FIND_PACKAGE_NAME}
FOUND_VAR ${CMAKE_FIND_PACKAGE_NAME}_FOUND
REQUIRED_VARS OPENTELEMETRY_CPP_INCLUDE_DIRS OPENTELEMETRY_CPP_LIBRARIES)

if(${CMAKE_FIND_PACKAGE_NAME}_FOUND)
set(OPENTELEMETRY_CPP_FOUND
${${CMAKE_FIND_PACKAGE_NAME}_FOUND}
CACHE BOOL "whether opentelemetry-cpp is found" FORCE)
else()
unset(OPENTELEMETRY_CPP_FOUND)
unset(OPENTELEMETRY_CPP_FOUND CACHE)
endif()
2 changes: 1 addition & 1 deletion cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ else()
message(
STATUS "opentelemetry-proto dependency satisfied by: github download")
if("${opentelemetry-proto}" STREQUAL "")
set(opentelemetry-proto "v0.20.0")
set(opentelemetry-proto "v1.0.0")
endif()
include(ExternalProject)
ExternalProject_Add(
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc/tracer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ void InitTracer()
std::vector<std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor>> processors;
processors.push_back(std::move(processor));
// Default is an always-on sampler.
std::shared_ptr<opentelemetry::sdk::trace::TracerContext> context =
std::unique_ptr<opentelemetry::sdk::trace::TracerContext> context =
opentelemetry::sdk::trace::TracerContextFactory::Create(std::move(processors));
std::shared_ptr<opentelemetry::trace::TracerProvider> provider =
opentelemetry::sdk::trace::TracerProviderFactory::Create(context);
opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(context));
// Set the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(provider);

Expand Down
4 changes: 2 additions & 2 deletions examples/http/tracer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ void InitTracer()
std::vector<std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor>> processors;
processors.push_back(std::move(processor));
// Default is an always-on sampler.
std::shared_ptr<opentelemetry::sdk::trace::TracerContext> context =
std::unique_ptr<opentelemetry::sdk::trace::TracerContext> context =
opentelemetry::sdk::trace::TracerContextFactory::Create(std::move(processors));
std::shared_ptr<opentelemetry::trace::TracerProvider> provider =
opentelemetry::sdk::trace::TracerProviderFactory::Create(context);
opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(context));
// Set the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(provider);

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
7 changes: 4 additions & 3 deletions ext/test/w3c_tracecontext_test/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ void initTracer()
new trace_sdk::SimpleSpanProcessor(std::move(exporter)));
std::vector<std::unique_ptr<trace_sdk::SpanProcessor>> processors;
processors.push_back(std::move(processor));
auto context = std::make_shared<trace_sdk::TracerContext>(std::move(processors));
auto provider =
nostd::shared_ptr<trace_api::TracerProvider>(new trace_sdk::TracerProvider(context));
auto context = std::unique_ptr<trace_sdk::TracerContext>(
new trace_sdk::TracerContext(std::move(processors)));
auto provider = nostd::shared_ptr<trace_api::TracerProvider>(
new trace_sdk::TracerProvider(std::move(context)));
// Set the global trace provider
trace_api::Provider::SetTracerProvider(provider);
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/include/opentelemetry/sdk/logs/logger_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# include <memory>
# include <vector>

# include "opentelemetry/sdk/logs/processor.h"
# include "opentelemetry/sdk/resource/resource.h"
# include "opentelemetry/version.h"

Expand All @@ -17,7 +18,6 @@ namespace sdk
{
namespace logs
{
class LogRecordProcessor;

/**
* A class which stores the LoggerContext context.
Expand All @@ -40,10 +40,10 @@ class LoggerContext
opentelemetry::sdk::resource::Resource::Create({})) noexcept;

/**
* Attaches a log processor to list of configured processors to this tracer context.
* Attaches a log processor to list of configured processors to this logger context.
* Processor once attached can't be removed.
* @param processor The new log processor for this tracer. This must not be
* a nullptr. Ownership is given to the `TracerContext`.
* a nullptr. Ownership is given to the `LoggerContext`.
*
* Note: This method is not thread safe.
*/
Expand Down
6 changes: 3 additions & 3 deletions sdk/include/opentelemetry/sdk/logs/logger_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider

/**
* Initialize a new logger provider with a specified context
* @param context The shared logger configuration/pipeline for this provider.
* @param context The owned logger configuration/pipeline for this provider.
*/
explicit LoggerProvider(std::shared_ptr<sdk::logs::LoggerContext> context) noexcept;
explicit LoggerProvider(std::unique_ptr<LoggerContext> context) noexcept;

~LoggerProvider() override;

Expand Down Expand Up @@ -106,7 +106,7 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider
private:
// order of declaration is important here - loggers should destroy only after context.
std::vector<std::shared_ptr<opentelemetry::sdk::logs::Logger>> loggers_;
std::shared_ptr<sdk::logs::LoggerContext> context_;
std::shared_ptr<LoggerContext> context_;
std::mutex lock_;
};
} // namespace logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class OPENTELEMETRY_EXPORT LoggerProviderFactory
* Create a LoggerProvider.
*/
static std::unique_ptr<opentelemetry::logs::LoggerProvider> Create(
std::shared_ptr<sdk::logs::LoggerContext> context);
std::unique_ptr<LoggerContext> context);
};

} // namespace logs
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: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/trace/tracer_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider

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

~TracerProvider() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class OPENTELEMETRY_EXPORT TracerProviderFactory
/* Create with a tracer context. */

static std::unique_ptr<opentelemetry::trace::TracerProvider> Create(
std::shared_ptr<TracerContext> context);
std::unique_ptr<TracerContext> context);
};

} // namespace trace
Expand Down
14 changes: 6 additions & 8 deletions sdk/src/logs/logger_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,27 @@ LoggerProvider::LoggerProvider(std::unique_ptr<LogRecordProcessor> &&processor,
{
std::vector<std::unique_ptr<LogRecordProcessor>> processors;
processors.emplace_back(std::move(processor));
context_ = std::make_shared<sdk::logs::LoggerContext>(std::move(processors), std::move(resource));
context_ = std::make_shared<LoggerContext>(std::move(processors), std::move(resource));
OTEL_INTERNAL_LOG_DEBUG("[LoggerProvider] LoggerProvider created.");
}

LoggerProvider::LoggerProvider(std::vector<std::unique_ptr<LogRecordProcessor>> &&processors,
opentelemetry::sdk::resource::Resource resource) noexcept
: context_{
std::make_shared<sdk::logs::LoggerContext>(std::move(processors), std::move(resource))}
: context_{std::make_shared<LoggerContext>(std::move(processors), std::move(resource))}
{}

LoggerProvider::LoggerProvider() noexcept
: context_{std::make_shared<sdk::logs::LoggerContext>(
std::vector<std::unique_ptr<LogRecordProcessor>>{})}
: context_{std::make_shared<LoggerContext>(std::vector<std::unique_ptr<LogRecordProcessor>>{})}
{}

LoggerProvider::LoggerProvider(std::shared_ptr<sdk::logs::LoggerContext> context) noexcept
: context_{context}
LoggerProvider::LoggerProvider(std::unique_ptr<LoggerContext> context) noexcept
: context_(std::move(context))
{}

LoggerProvider::~LoggerProvider()
{
// Logger hold the shared pointer to the context. So we can not use destructor of LoggerContext to
// Shutdown and flush all pending recordables when we hasve more than one loggers.These
// Shutdown and flush all pending recordables when we have more than one loggers. These
// recordables may use the raw pointer of instrumentation_scope_ in Logger
if (context_)
{
Expand Down
6 changes: 4 additions & 2 deletions sdk/src/logs/logger_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef ENABLE_LOGS_PREVIEW

# include "opentelemetry/sdk/logs/logger_provider_factory.h"
# include "opentelemetry/sdk/logs/logger_context.h"
# include "opentelemetry/sdk/logs/logger_provider.h"
# include "opentelemetry/sdk/resource/resource.h"

Expand Down Expand Up @@ -46,9 +47,10 @@ std::unique_ptr<opentelemetry::logs::LoggerProvider> LoggerProviderFactory::Crea
}

std::unique_ptr<opentelemetry::logs::LoggerProvider> LoggerProviderFactory::Create(
std::shared_ptr<sdk::logs::LoggerContext> context)
std::unique_ptr<LoggerContext> context)
{
std::unique_ptr<opentelemetry::logs::LoggerProvider> provider(new LoggerProvider(context));
std::unique_ptr<opentelemetry::logs::LoggerProvider> provider(
new LoggerProvider(std::move(context)));
return provider;
}

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
Loading

0 comments on commit f7c5320

Please sign in to comment.