Skip to content

Conversation

@martincostello
Copy link
Member

@martincostello martincostello commented Jan 27, 2026

Changes

  • Avoid array lookup and implicit bounds checks by converting to a switch statement.
  • Apply analyzer suggestions to simplify/modernize code.
  • Improve test coverage for metric mapping (mostly written by Copilot).

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

- Avoid array lookup and implicit bounds checks by converting to a switch statement.
- Apply analyzer suggestions to simplify/modernize code.
@github-actions github-actions bot added the pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package label Jan 27, 2026
@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.27%. Comparing base (496e4ac) to head (d04cc43).
⚠️ Report is 12 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6851      +/-   ##
==========================================
+ Coverage   86.90%   87.27%   +0.36%     
==========================================
  Files         263      263              
  Lines       12382    12385       +3     
==========================================
+ Hits        10761    10809      +48     
+ Misses       1621     1576      -45     
Flag Coverage Δ
unittests-Project-Experimental 87.20% <100.00%> (+0.47%) ⬆️
unittests-Project-Stable 87.17% <100.00%> (+0.35%) ⬆️
unittests-UnstableCoreLibraries-Experimental 89.42% <100.00%> (+3.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ometheus.HttpListener/Internal/PrometheusMetric.cs 99.31% <100.00%> (+25.18%) ⬆️

... and 4 files with indirect coverage changes

Add unit tests for missing coverage of metric conversions.
@martincostello martincostello marked this pull request as ready for review January 27, 2026 16:40
@martincostello martincostello requested a review from a team as a code owner January 27, 2026 16:40
Copilot AI review requested due to automatic review settings January 27, 2026 16:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the GetPrometheusType method by replacing array lookup with a switch statement, applies modern C# patterns to simplify method bodies, and significantly expands test coverage for metric unit mapping.

Changes:

  • Replaced array lookup in GetPrometheusType with a switch statement to avoid bounds checks and improve clarity
  • Converted several methods to expression-bodied members for modern, concise code
  • Added comprehensive test coverage for unit mapping, metric type mapping, and edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusMetric.cs Replaced array-based metric type lookup with switch statement; converted methods to expression-bodied members
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusMetricTests.cs Added 225 lines of comprehensive unit tests covering metric unit mapping, type conversion, and edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rajkumar-rangaraj rajkumar-rangaraj added this pull request to the merge queue Jan 28, 2026
Merged via the queue into open-telemetry:main with commit cfc2d0c Jan 28, 2026
126 of 128 checks passed
@martincostello martincostello deleted the avoid-array-lookup branch January 28, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants