[Exporter.Prometheus] Fix number formatting - #7589
Conversation
Fix incorrectly formatted floating point numbers caused by a misunderstanding of https://prometheus.io/docs/specs/om/open_metrics_spec/#considerations-canonical-numbers. Fixes open-telemetry#7585.
Add a clarifying comment as suggested by Copilot review.
Add PR number.
Pull request dashboard statusMerged · refreshed 2026-08-12 22:39 UTC Status above doesn't look right?
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7589 +/- ##
=======================================
Coverage 90.51% 90.52%
=======================================
Files 292 292
Lines 16197 16215 +18
=======================================
+ Hits 14661 14678 +17
- Misses 1536 1537 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Verify the histogram bucket boundaries round-trip.
There was a problem hiding this comment.
Pull request overview
This PR fixes floating-point number formatting in the Prometheus exporters’ text serialization to use the shortest round-trippable representation for sample values, and to correctly render OpenMetrics canonical numbers for histogram le and summary quantile label values. It updates unit/integration/fuzz tests and changelogs to lock in the corrected behavior and prevent regressions.
Changes:
- Updated Prometheus text serialization to avoid
G17-style over-precision padding and to correctly render canonical numbers forle/quantile. - Added/updated unit, integration, fuzz tests and snapshot baselines to validate round-tripping and boundary rendering.
- Added CHANGELOG entries for both Prometheus.HttpListener and Prometheus.AspNetCore packages.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.HistogramWithFractionalBoundaries_useOpenMetrics=True.verified.txt | New snapshot baseline for histogram fractional boundary rendering (OpenMetrics). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.HistogramWithFractionalBoundaries_useOpenMetrics=False.verified.txt | New snapshot baseline for histogram fractional boundary rendering (Prometheus text). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs | Updates numeric formatting expectations and adds regression tests for round-tripping/precision. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusIntegrationTests.cs | Adjusts integration test bucket boundaries to cover more rendered shapes. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.FuzzTests/PrometheusSerializerFuzzTests.cs | Updates fuzz property to validate round-tripping without unnecessary padding. |
| test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusIntegrationTests.cs | Adds assertions to validate bucket boundary round-tripping through Prometheus API. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/TextFormatSerializer.cs | Core implementation change: shortest round-trippable formatting and corrected canonical number rendering. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md | Adds Unreleased entries describing formatting/canonical-number fixes. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md | Adds Unreleased entries describing formatting/canonical-number fixes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add a timeout to test container start-up and dispose. - Remove redundant port binding. - Do not wait indefinitely for Prometheus test container logs. - Collect hang dumps from tests.
Fixes #7585
Changes
Fix incorrectly formatted floating point numbers caused by a misunderstanding of Canonical Numbers.
Specifically this part:
I took it to mean to use G17 to format things, but that over-specifies the precision and causes non-exact round-tripping issues as described in the linked discussion.
Re-running the benchmarks locally don't show any regression in terms of runtime or allocation due to the use of
stackalloc.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes