diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index 3d296602b8..1172cf0eb2 100644 --- a/.github/workflows/clang-tidy.yaml +++ b/.github/workflows/clang-tidy.yaml @@ -17,9 +17,9 @@ jobs: matrix: include: - cmake_options: all-options-abiv1-preview - warning_limit: 142 + warning_limit: 139 - cmake_options: all-options-abiv2-preview - warning_limit: 152 + warning_limit: 149 env: CC: /usr/bin/clang-22 CXX: /usr/bin/clang++-22 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8baba4503c..7917275c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,10 @@ Increment the: * [CODE HEALTH] Fix remaining misc-override-with-different-visibility warnings [#4280](https://github.com/open-telemetry/opentelemetry-cpp/pull/4280) +* [CODE HEALTH] Move SDK common and logs test helpers into anonymous + namespaces + [#4302](https://github.com/open-telemetry/opentelemetry-cpp/pull/4302) + Breaking changes: * [METRICS SDK] Rename Base2 Exponential Histogram Aggregation config field diff --git a/sdk/test/common/global_log_handle_singleton_lifetime_test.cc b/sdk/test/common/global_log_handle_singleton_lifetime_test.cc index 1aac3ee412..b5f5e64daf 100644 --- a/sdk/test/common/global_log_handle_singleton_lifetime_test.cc +++ b/sdk/test/common/global_log_handle_singleton_lifetime_test.cc @@ -11,6 +11,9 @@ #include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/common/global_log_handler.h" +namespace +{ + class GlobalLogHandlerChecker { public: @@ -19,9 +22,12 @@ class GlobalLogHandlerChecker { using opentelemetry::sdk::common::internal_log::GlobalLogHandler; auto handle = GlobalLogHandler::GetLogHandler(); - if (handle && custom_handler_destroyed) + // The checker must outlive the global handler. Fail if it is destroyed first + // (custom_handler_destroyed still false) or if the handler is somehow still reachable + // (handle non-null). + if (!custom_handler_destroyed || handle) { - OTEL_INTERNAL_LOG_ERROR("GlobalLogHandler should be destroyed here"); + OTEL_INTERNAL_LOG_ERROR("GlobalLogHandler must be destroyed before the checker"); abort(); } std::cout << "GlobalLogHandlerChecker destroyed and check pass.\n"; @@ -38,14 +44,11 @@ class GlobalLogHandlerChecker }; bool GlobalLogHandlerChecker::custom_handler_destroyed = false; -namespace -{ static GlobalLogHandlerChecker &ConstructChecker() { static GlobalLogHandlerChecker checker; return checker; } -} // namespace class CustomLogHandler : public opentelemetry::sdk::common::internal_log::LogHandler { @@ -112,3 +115,5 @@ TEST(GlobalLogHandleSingletonTest, Lifetime) EXPECT_TRUE(!!handle); } } + +} // namespace diff --git a/sdk/test/logs/logger_provider_set_test.cc b/sdk/test/logs/logger_provider_set_test.cc index aa899bbcbd..bb849549fb 100644 --- a/sdk/test/logs/logger_provider_set_test.cc +++ b/sdk/test/logs/logger_provider_set_test.cc @@ -28,6 +28,9 @@ namespace nostd = opentelemetry::nostd; namespace logs_api = opentelemetry::logs; namespace logs_sdk = opentelemetry::sdk::logs; +namespace +{ + class TestProvider : public LoggerProvider { public: @@ -86,3 +89,5 @@ TEST(Provider, MultipleLoggerProviders) ASSERT_NE(logs_api::Provider::GetLoggerProvider(), tf); } + +} // namespace