Skip to content

[Exporter.Prometheus] Fix spec compliance#7491

Merged
martincostello merged 3 commits into
open-telemetry:mainfrom
martincostello:fix-prometheus-spec-compliance
Jul 9, 2026
Merged

[Exporter.Prometheus] Fix spec compliance#7491
martincostello merged 3 commits into
open-telemetry:mainfrom
martincostello:fix-prometheus-spec-compliance

Conversation

@martincostello

Copy link
Copy Markdown
Member

Changes

Fix some minor findings from checking the Prometheus exporters against the specifications with Claude and Copilot:

  • Do not emit redundant comments for PrometheusText format.
  • Make Accept header parsing consistent between AspNetCore and HttpListener implementations.
  • Fix incorrect fallback version for OpenMetrics.
  • Fix incorrect quotation mark escaping for HELP metadata.

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)

- Do not emit redundant comments for PrometheusText.
- Make `Accept` header parsing consistent between implementations.
- Fix incorrect fallback version for OpenMetrics.
- Fix incorrect quotation mark escaping for `HELP` metadata.
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (d84d2af) to head (ab6e817).
⚠️ Report is 16 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7491      +/-   ##
==========================================
- Coverage   90.29%   90.29%   -0.01%     
==========================================
  Files         287      288       +1     
  Lines       15617    15926     +309     
==========================================
+ Hits        14102    14380     +278     
- Misses       1515     1546      +31     
Flag Coverage Δ
unittests-Project-Experimental 90.33% <100.00%> (+0.01%) ⬆️
unittests-Project-Stable 90.21% <100.00%> (-0.05%) ⬇️
unittests-UnstableCoreLibraries-Experimental 50.99% <100.00%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
...metheus.AspNetCore/PrometheusExporterMiddleware.cs 100.00% <100.00%> (ø)
...s.HttpListener/Internal/PrometheusHeadersParser.cs 98.76% <100.00%> (-0.03%) ⬇️
...ner/Internal/Shared/PrometheusCollectionManager.cs 92.37% <100.00%> (ø)
...rnal/Shared/Serialization/OpenMetricsSerializer.cs 100.00% <100.00%> (ø)
...l/Shared/Serialization/PrometheusTextSerializer.cs 100.00% <100.00%> (ø)
...ernal/Shared/Serialization/TextFormatSerializer.cs 99.49% <100.00%> (-0.01%) ⬇️

... and 5 files with indirect coverage changes

@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 Jul 7, 2026
@martincostello
martincostello marked this pull request as ready for review July 7, 2026 16:43
@martincostello
martincostello requested a review from a team as a code owner July 7, 2026 16:43
Copilot AI review requested due to automatic review settings July 7, 2026 16:43

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

This PR improves Prometheus exporter spec compliance across the HttpListener and ASP.NET Core implementations by aligning content negotiation and tightening text/OpenMetrics exposition output to match their respective specifications.

Changes:

  • Removed Prometheus text-format-only “redundant” output (# UNIT lines and # EOF terminator), while keeping # EOF for OpenMetrics.
  • Made Accept header parsing consistent between ASP.NET Core middleware and HttpListener negotiation, including correct OpenMetrics default version selection.
  • Fixed escaping behavior for # HELP metadata so OpenMetrics escapes double quotes while Prometheus text does not.

Reviewed changes

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

Show a summary per file
File Description
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.WriteMetric_SerializesMultibyteUtf8MetricNameProvidedByView_escaping=values_useOpenMetrics=False.verified.txt Updates expected Prometheus text output to omit # UNIT.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.WriteMetric_SerializesMultibyteUtf8MetricNameProvidedByView_escaping=underscores_useOpenMetrics=False.verified.txt Updates expected Prometheus text output to omit # UNIT.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.WriteMetric_SerializesMultibyteUtf8MetricNameProvidedByView_escaping=dots_useOpenMetrics=False.verified.txt Updates expected Prometheus text output to omit # UNIT.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.WriteMetric_SerializesMultibyteUtf8MetricNameProvidedByView_escaping=allow-utf-8_useOpenMetrics=False.verified.txt Updates expected Prometheus text output to omit # UNIT.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithTextPlainResponseAndMeterTags.verified.text Updates expected Prometheus text output to omit # UNIT and # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithTextPlainResponse.verified.text Updates expected Prometheus text output to omit # UNIT and # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithNoAcceptHeaderAndMeterTags.verified.text Updates expected Prometheus text output to omit # UNIT and # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithNoAcceptHeader.verified.text Updates expected Prometheus text output to omit # UNIT and # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.MetricUnitDiscoveredLaterIsWrittenBeforeSamples.verified.txt Updates expected Prometheus text output to omit # UNIT and # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.MetricMetadataDiscoveredLaterIsWrittenBeforeSamples.verified.txt Updates expected Prometheus text output to omit # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.MetricHelpAndUnitDiscoveredTogetherLaterAreBothWrittenBeforeSamples.verified.txt Updates expected Prometheus text output to omit # UNIT and # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.GaugeZeroDimensionWithUnit.verified.txt Updates expected Prometheus text output to omit # UNIT.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.GaugeZeroDimensionWithDescriptionAndUnit.verified.txt Updates expected Prometheus text output to omit # UNIT.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.ExponentialHistogramsAreIgnored.verified.txt Updates expected Prometheus text output to omit # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.DuplicateMetricMetadataIsWrittenOncePerScrape.verified.txt Updates expected Prometheus text output to omit # UNIT and # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.BufferSizeIncreasesWithLotOfMetrics.verified.text Updates large expected Prometheus text output to omit repeated # UNIT and trailing # EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs Adds/adjusts unit tests for HELP quote escaping and Prometheus-vs-OpenMetrics UNIT behavior.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs Updates integration expectations for OpenMetrics 1.0.0 content-type (incl. escaping) and removes Prometheus # UNIT/# EOF.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusAcceptHeaders.cs Expands Accept-header test cases to validate OpenMetrics 1.0.0 fallback and escaping defaults.
test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusIntegrationTests.cs Updates assertions to no longer expect # EOF in responses and still require newline termination.
test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs Updates expected payload/content-type to match new negotiation and Prometheus text output rules.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/TextFormatSerializer.cs Makes EOF/unit writing format-specific and routes HELP through escaping logic that can optionally escape quotes.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/PrometheusTextSerializer.cs Disables UNIT emission and HELP-quote escaping for Prometheus text format.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/OpenMetricsSerializer.cs Ensures OpenMetrics HELP escapes quotes and output terminates with # EOF.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusCollectionManager.cs Uses the negotiated serializer to write EOF (or not) appropriately.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusHeadersParser.cs Fixes OpenMetrics negotiation fallback to 1.0.0 and keeps behavior aligned with escaping requirements.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Adds Unreleased entries describing the spec compliance fixes.
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs Aligns ASP.NET Core Accept parsing with HttpListener rules (q parsing, OpenMetrics fallback, stable preference selection).
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Adds Unreleased entries describing the spec compliance fixes.

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

@martincostello
martincostello enabled auto-merge July 7, 2026 18:44
@martincostello martincostello added this to the v1.17.0 milestone Jul 8, 2026
@martincostello martincostello added the review-priority Should be prioritized for review label Jul 8, 2026
This was referenced Jul 19, 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