diff --git a/sdk/include/opentelemetry/sdk/common/global_log_handler.h b/sdk/include/opentelemetry/sdk/common/global_log_handler.h index 99cf48b820..e8291322b9 100644 --- a/sdk/include/opentelemetry/sdk/common/global_log_handler.h +++ b/sdk/include/opentelemetry/sdk/common/global_log_handler.h @@ -134,11 +134,10 @@ class GlobalLogHandler OPENTELEMETRY_END_NAMESPACE /** - * We can not decide the destroying order of signaltons. - * Which means, the destructors of other singletons (GlobalLogHandler,TracerProvider and etc.) - * may be called after destroying of global LogHandler and use OTEL_INTERNAL_LOG_* in it.We can do - * nothing but ignore the log in this situation. - */ + * GlobalLogHandler and TracerProvider/MeterProvider/LoggerProvider are lazy sigletons. + * To ensure that GlobalLogHandler is the first one to be initialized (and so last to be + * destroyed), it is first used inside the constructors of TraceProvider, MeterProvider + * and LoggerProvider for debug logging. */ #define OTEL_INTERNAL_LOG_DISPATCH(level, message, attributes) \ do \ { \ diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index ddd4d0cbde..6f806d5be9 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -4,6 +4,7 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/sdk/logs/logger_provider.h" +# include "opentelemetry/sdk/common/global_log_handler.h" # include # include @@ -26,6 +27,7 @@ LoggerProvider::LoggerProvider(std::unique_ptr &&processor, std::vector> processors; processors.emplace_back(std::move(processor)); context_ = std::make_shared(std::move(processors), std::move(resource)); + OTEL_INTERNAL_LOG_DEBUG("[LoggerProvider] LoggerProvider created."); } LoggerProvider::LoggerProvider(std::vector> &&processors, diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 6a06f9d2d8..051ee7269e 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -24,7 +24,9 @@ MeterProvider::MeterProvider(std::shared_ptr context) noexcept : c MeterProvider::MeterProvider(std::unique_ptr views, sdk::resource::Resource resource) noexcept : context_(std::make_shared(std::move(views), resource)) -{} +{ + OTEL_INTERNAL_LOG_DEBUG("[MeterProvider] MeterProvider created."); +} nostd::shared_ptr MeterProvider::GetMeter( nostd::string_view name, diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index bdce3153c5..b5eed6312f 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk_config.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -14,7 +15,9 @@ namespace trace_api = opentelemetry::trace; TracerProvider::TracerProvider(std::shared_ptr context) noexcept : context_{context} -{} +{ + OTEL_INTERNAL_LOG_DEBUG("[TracerProvider] TracerProvider created."); +} TracerProvider::TracerProvider(std::unique_ptr processor, resource::Resource resource,