From 42187e6dc5e79fe6970adf8f7189cc10490cb6af Mon Sep 17 00:00:00 2001 From: andyning Date: Mon, 6 Nov 2023 14:42:19 +0800 Subject: [PATCH] Fix core dump issue in OTEL_INTERNAL_LOG_DISPATCH macro (#2393) --- CHANGELOG.md | 2 + .../sdk/common/global_log_handler.h | 37 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9acee42235..10087a741a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ Increment the: [#2385](https://github.com/open-telemetry/opentelemetry-cpp/pull/2385) * [API] Add a new AddLink() operation to Span [#2380](https://github.com/open-telemetry/opentelemetry-cpp/pull/2380) +* [SDK] Fix core dump issue in OTEL_INTERNAL_LOG_DISPATCH macro + [#2394](https://github.com/open-telemetry/opentelemetry-cpp/pull/2394) Important changes: diff --git a/sdk/include/opentelemetry/sdk/common/global_log_handler.h b/sdk/include/opentelemetry/sdk/common/global_log_handler.h index a36bd4a8a3..8c75180dcf 100644 --- a/sdk/include/opentelemetry/sdk/common/global_log_handler.h +++ b/sdk/include/opentelemetry/sdk/common/global_log_handler.h @@ -137,24 +137,25 @@ OPENTELEMETRY_END_NAMESPACE * 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 \ - { \ - using opentelemetry::sdk::common::internal_log::GlobalLogHandler; \ - using opentelemetry::sdk::common::internal_log::LogHandler; \ - if (level > GlobalLogHandler::GetLogLevel()) \ - { \ - break; \ - } \ - const opentelemetry::nostd::shared_ptr &log_handler = \ - GlobalLogHandler::GetLogHandler(); \ - if (!log_handler) \ - { \ - break; \ - } \ - std::stringstream tmp_stream; \ - tmp_stream << message; \ - log_handler->Handle(level, __FILE__, __LINE__, tmp_stream.str().c_str(), attributes); \ +#define OTEL_INTERNAL_LOG_DISPATCH(level, message, attributes) \ + do \ + { \ + using opentelemetry::sdk::common::internal_log::GlobalLogHandler; \ + using opentelemetry::sdk::common::internal_log::LogHandler; \ + if (level > GlobalLogHandler::GetLogLevel()) \ + { \ + break; \ + } \ + const opentelemetry::nostd::shared_ptr &log_handler = \ + GlobalLogHandler::GetLogHandler(); \ + if (!log_handler) \ + { \ + break; \ + } \ + std::stringstream tmp_stream; \ + tmp_stream << message; \ + std::string tmp_string = tmp_stream.str(); \ + log_handler->Handle(level, __FILE__, __LINE__, tmp_string.c_str(), attributes); \ } while (false); #define OTEL_INTERNAL_LOG_GET_3RD_ARG(arg1, arg2, arg3, ...) arg3