Skip to content

[CODE HEALTH] Resolve multiple clang tidy warnings - #4492

Open
dbarker wants to merge 17 commits into
open-telemetry:mainfrom
dbarker:fix_multiple_clang_tidy_warnings
Open

[CODE HEALTH] Resolve multiple clang tidy warnings#4492
dbarker wants to merge 17 commits into
open-telemetry:mainfrom
dbarker:fix_multiple_clang_tidy_warnings

Conversation

@dbarker

@dbarker dbarker commented Aug 27, 2026

Copy link
Copy Markdown
Member

Contributes to #2053

Changes

resolves the following warnings:

  • modernize-use-using - 8 warnings
  • cppcoreguidelines-use-enum-class - 7 warnings
  • bugprone-random-generator-seed - 5 warnings
  • modernize-deprecated-headers - 4 warnings
  • misc-predictable-rand - 3 warnings
  • bugprone-derived-method-shadowing-base-method - 3 warnings
  • bugprone-unintended-char-ostream-output - 2 warnings
  • performance-move-const-arg - 2 warnings
  • cppcoreguidelines-macro-to-enum - 2 warnings
  • abseil-string-find-startswith - 1 warning
  • misc-use-internal-linkage - 1 warning

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@dbarker dbarker changed the title [CODE HEALTH] Fix multiple clang tidy warnings [CODE HEALTH] Resolve multiple clang tidy warnings Aug 27, 2026
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.17%. Comparing base (7403a6d) to head (7a14394).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4492      +/-   ##
==========================================
- Coverage   83.18%   83.17%   -0.00%     
==========================================
  Files         520      520              
  Lines       20321    20321              
==========================================
- Hits        16901    16899       -2     
- Misses       3420     3422       +2     
Files with missing lines Coverage Δ
api/include/opentelemetry/nostd/string_view.h 98.28% <ø> (ø)
...nclude/opentelemetry/ext/http/server/http_server.h 66.67% <ø> (ø)
...clude/opentelemetry/ext/http/server/socket_tools.h 95.68% <ø> (ø)
...include/opentelemetry/sdk/common/attribute_utils.h 95.63% <ø> (ø)
...pentelemetry/sdk/metrics/exemplar/reservoir_cell.h 97.83% <ø> (ø)
...ntelemetry/sdk/metrics/state/sync_metric_storage.h 84.94% <100.00%> (ø)
...ntelemetry/sdk/metrics/view/attributes_processor.h 92.11% <ø> (ø)
sdk/src/resource/resource_detector.cc 100.00% <ø> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbarker
dbarker marked this pull request as ready for review August 27, 2026 21:56
@dbarker
dbarker requested a review from a team as a code owner August 27, 2026 21:56

@denizariyan denizariyan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup, thanks!

Comment thread api/include/opentelemetry/version.h
{
std::array<int, 1000> batch{};
std::default_random_engine generator;
std::default_random_engine generator{std::random_device{}()};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is from a bugprone-random-generator-seed right? That rule is more about security related RNG which needs to be random while a benchmark usually wants to not be random.

With actual randomness, the benchmarks would have non-reproducible input which we should avoid so that a before/after comparison doesn't have a potential to be affected by the input unintentionally.

For this case ideally in a benchmark we:

  • Don't use default_random_engine as it's implementation defined and differs across implementations
  • Use an explicitly set seed instead of relying on implementation defaults or an actual random device

The first point is not new now so I think we could keep it for now but I think we should not use a random device now. Applies similarly to other random usage changes in this PR. WDYT?

e.g:

Suggested change
std::default_random_engine generator{std::random_device{}()};
// NOLINTNEXTLINE(bugprone-random-generator-seed): keep input reproducible
std::default_random_engine generator{42};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great analysis. Yes a fixed seed would be better. As you noted there is some room for improvement throughout the benchmarks outside this PR. Please share if you find any other cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I also agree a fixed seed is better for test code.

Comment on lines +45 to +49
const std::string service_name = detail::GetServiceName();
const std::string unknown_service_prefix = "unknown_service:";
if (service_name.substr(0, unknown_service_prefix.size()) == unknown_service_prefix)
{
EXPECT_GT(service_name.size(), std::string{"unknown_service:"}.size());
EXPECT_GT(service_name.size(), unknown_service_prefix.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is this due to abseil-string-find-startswith? Maybe we could just disable the rule similar to abseil-string-find-str-contains since the rule suggests using abseil helpers which we don't have here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good feedback! Yes I think it is better to disable the abseil-string-find-startswith check. This check will come back in the modernize form once building with c++20

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the cleanup.

See suggestions from @denizariyan on fixed seeds in benchmarks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants