Skip to content

[Exporter.Prometheus] Fix OpenMetrics histograms#7221

Merged
martincostello merged 8 commits into
open-telemetry:mainfrom
martincostello:omit-negative-sum-count-for-openmetrics
May 5, 2026
Merged

[Exporter.Prometheus] Fix OpenMetrics histograms#7221
martincostello merged 8 commits into
open-telemetry:mainfrom
martincostello:omit-negative-sum-count-for-openmetrics

Conversation

@martincostello

Copy link
Copy Markdown
Member

Changes

Omit histogram _sum and _count in OpenMetrics when negative bucket thresholds are present.

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)

Omit histogram `_sum` and `_count` in OpenMetrics when negative bucket thresholds are present.
@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package labels Apr 29, 2026
Comment thread src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Outdated
Comment thread src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Outdated
@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.92%. Comparing base (c0f7fb4) to head (7c58e78).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7221      +/-   ##
==========================================
- Coverage   89.98%   89.92%   -0.06%     
==========================================
  Files         272      272              
  Lines       13643    13649       +6     
==========================================
- Hits        12276    12274       -2     
- Misses       1367     1375       +8     
Flag Coverage Δ
unittests-Project-Experimental 89.77% <100.00%> (-0.10%) ⬇️
unittests-Project-Stable 89.81% <100.00%> (-0.15%) ⬇️
unittests-UnstableCoreLibraries-Experimental 46.14% <100.00%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
...s.HttpListener/Internal/PrometheusSerializerExt.cs 98.91% <100.00%> (+0.04%) ⬆️

... and 4 files with indirect coverage changes

@martincostello martincostello marked this pull request as ready for review April 29, 2026 20:22
@martincostello martincostello requested a review from a team as a code owner April 29, 2026 20:22
Copilot AI review requested due to automatic review settings April 29, 2026 20:22

Copilot AI 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.

Pull request overview

Fixes OpenMetrics histogram serialization in the Prometheus exporters to comply with the OpenMetrics spec when explicit bucket boundaries include negative thresholds.

Changes:

  • Detect negative histogram bucket bounds during serialization when OpenMetrics output is requested.
  • Omit histogram _sum and _count series in OpenMetrics output when negative bucket thresholds are present.
  • Add a unit test validating _sum/_count omission and update changelogs for both Prometheus exporters.

Reviewed changes

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

File Description
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs Adds coverage ensuring OpenMetrics output omits _sum and _count when buckets include negative bounds.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs Implements conditional suppression of _sum/_count for OpenMetrics histograms with negative bucket thresholds.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Documents the behavioral change in the HttpListener exporter changelog.
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Documents the behavioral change in the AspNetCore exporter changelog (shared serializer implementation).

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

This was referenced Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants