From 3d26b9b49c89ac065b2ff8a4047c87eb9ea31b74 Mon Sep 17 00:00:00 2001 From: thc1006 <84045975+thc1006@users.noreply.github.com> Date: Sat, 25 Jul 2026 02:03:31 +0800 Subject: [PATCH 1/3] [CODE HEALTH] Move remaining API test helpers into anonymous namespaces Six misc-use-internal-linkage sites, continuing from #4217 and #4286. logger_test.cc had an anonymous namespace already, with TestLogger just above it and TestProvider just below, so the existing namespace is extended to cover both rather than adding two more. string_test.cc is the same shape: its namespace closed immediately before SplitStringTestFixture, so the closing brace moves to the end of the file. The two provider_test.cc files get a namespace around the test body. In the logs one that puts the deprecated-declaration pragma push and pop pair inside the namespace, which is fine since both ends stay on the same side of the boundary. Worth noting that api/test/logs holds two different classes both named TestProvider, in logger_test.cc and provider_test.cc. They are in the same Bazel package, so giving them internal linkage also removes a latent one definition rule hazard. Part of #4196 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com> --- api/test/logs/logger_test.cc | 10 +++++----- api/test/logs/provider_test.cc | 5 +++++ api/test/trace/propagation/detail/string_test.cc | 3 ++- api/test/trace/provider_test.cc | 5 +++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 932a28455c..93ba579a8f 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -260,6 +260,9 @@ TEST(Logger, EventLogMethodOverloads) #endif +namespace +{ + // Define a basic Logger class class TestLogger : public Logger { @@ -282,9 +285,6 @@ class TestLogger : public Logger } }; -namespace -{ - class EnablementAwareTestLogRecord : public opentelemetry::logs::LogRecord { public: @@ -455,8 +455,6 @@ class EnablementAwareTestLogger : public Logger bool enabled_impl_result_; }; -} // namespace - // Define a basic LoggerProvider class that returns an instance of the logger class defined above class TestProvider : public LoggerProvider { @@ -678,3 +676,5 @@ TEST(Logger, EmitLogRecordWithTracePartsInArgsRoutesSpanContextVariantToEnabled) EXPECT_EQ(logger.last_span_context_.trace_flags(), trace_flags); } #endif // OPENTELEMETRY_ABI_VERSION_NO >= 2 + +} // namespace diff --git a/api/test/logs/provider_test.cc b/api/test/logs/provider_test.cc index 817092b4b6..51b916e274 100644 --- a/api/test/logs/provider_test.cc +++ b/api/test/logs/provider_test.cc @@ -28,6 +28,9 @@ using opentelemetry::logs::Provider; using opentelemetry::nostd::shared_ptr; namespace nostd = opentelemetry::nostd; +namespace +{ + class TestProvider : public LoggerProvider { public: @@ -167,3 +170,5 @@ TEST(NoopEventLoggerProvider, CreateNoopEventLogger) # endif #endif + +} // namespace diff --git a/api/test/trace/propagation/detail/string_test.cc b/api/test/trace/propagation/detail/string_test.cc index a647b9e2cf..42388f63f7 100644 --- a/api/test/trace/propagation/detail/string_test.cc +++ b/api/test/trace/propagation/detail/string_test.cc @@ -43,7 +43,6 @@ const SplitStringTestData split_string_test_cases[] = { {"foo ,bar, baz ", ',', 4, 3}, {"00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01", '-', 4, 4}, }; -} // namespace // Test fixture class SplitStringTestFixture : public ::testing::TestWithParam @@ -63,3 +62,5 @@ TEST_P(SplitStringTestFixture, SplitsAsExpected) INSTANTIATE_TEST_SUITE_P(SplitStringTestCases, SplitStringTestFixture, ::testing::ValuesIn(split_string_test_cases)); + +} // namespace diff --git a/api/test/trace/provider_test.cc b/api/test/trace/provider_test.cc index 9745c51191..7828c7d347 100644 --- a/api/test/trace/provider_test.cc +++ b/api/test/trace/provider_test.cc @@ -15,6 +15,9 @@ using opentelemetry::trace::TracerProvider; namespace nostd = opentelemetry::nostd; +namespace +{ + class TestProvider : public TracerProvider { public: @@ -49,3 +52,5 @@ TEST(Provider, SetTracerProvider) Provider::SetTracerProvider(tf); ASSERT_EQ(tf, Provider::GetTracerProvider()); } + +} // namespace From c208d7a54101a7ee60ca608059ece07255f2cf2e Mon Sep 17 00:00:00 2001 From: thc1006 <84045975+thc1006@users.noreply.github.com> Date: Sat, 25 Jul 2026 02:04:40 +0800 Subject: [PATCH 2/3] Lower the clang-tidy warning limit by the six sites removed abiv1 goes from 151 to 145. abiv2 goes from 161 to 156, five rather than six, because TestEventLoggerProvider sits behind deprecated-API pragmas and is only reported on abiv1. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com> --- .github/workflows/clang-tidy.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index 3d296602b8..c352cdecd5 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: 136 - cmake_options: all-options-abiv2-preview - warning_limit: 152 + warning_limit: 147 env: CC: /usr/bin/clang-22 CXX: /usr/bin/clang++-22 From 4dcdbc397ccf77498adc169b97939a771628383b Mon Sep 17 00:00:00 2001 From: thc1006 <84045975+thc1006@users.noreply.github.com> Date: Sat, 25 Jul 2026 02:05:37 +0800 Subject: [PATCH 3/3] Add CHANGELOG entry for #4301 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com> --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8baba4503c..819a741b73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ Increment the: namespaces [#4303](https://github.com/open-telemetry/opentelemetry-cpp/pull/4303) +* [CODE HEALTH] Move remaining API test helpers into anonymous namespaces + [#4301](https://github.com/open-telemetry/opentelemetry-cpp/pull/4301) + * [CODE HEALTH] Move metrics storage test fixtures into anonymous namespace [#4286](https://github.com/open-telemetry/opentelemetry-cpp/pull/4286)