Skip to content

[BUG] Fix random attribute selection in metrics foo example - #4585

Open
Anish701 wants to merge 3 commits into
open-telemetry:mainfrom
Anish701:fix-metrics-foo-random-attr
Open

Anish701 wants to merge 3 commits into
open-telemetry:mainfrom
Anish701:fix-metrics-foo-random-attr

Conversation

@Anish701

@Anish701 Anish701 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #4584

Changes

Update the get_random_attr method in examples/common/metrics_foo_library/foo_library.cc. Instead of random_int() % (labels.size() - 1), this PR updates it to be random_int() % labels.size(). This is so all key-value pairs in labels have an equal chance of being returned in the randomized method.

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

Signed-off-by: Anish701 <anish2sinha@gmail.com>
@Anish701
Anish701 requested a review from a team as a code owner September 16, 2026 20:28
@Anish701 Anish701 changed the title [BUG] fix get_random_attr method in metrics foo library [BUG] fix get_random_attr method in examples metrics foo library Sep 16, 2026
@Anish701 Anish701 changed the title [BUG] fix get_random_attr method in examples metrics foo library [BUG] Fix get_random_attr method in examples metrics foo library Sep 16, 2026
@Anish701 Anish701 changed the title [BUG] Fix get_random_attr method in examples metrics foo library [BUG] Fix random attribute selection in metrics foo example Sep 16, 2026
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.52%. Comparing base (e62f627) to head (a0010da).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4585   +/-   ##
=======================================
  Coverage   86.52%   86.52%           
=======================================
  Files         525      525           
  Lines       20464    20464           
=======================================
  Hits        17704    17704           
  Misses       2760     2760           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ThomsonTan ThomsonTan 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.

Could you please add an entry to the CHANGELOG.md?

Signed-off-by: Anish701 <anish2sinha@gmail.com>
@Anish701

Copy link
Copy Markdown
Contributor Author

Could you please add an entry to the CHANGELOG.md?

Sure thing! I've updated CHANGELOG.md with this fix

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.

[BUG] get_random_attr() in examples foo library never returns key5

3 participants