[Exporter.Prometheus] Update Accept/Content-Type handling to consider escaping#7209
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7209 +/- ##
==========================================
+ Coverage 89.86% 89.87% +0.01%
==========================================
Files 272 272
Lines 13489 13533 +44
==========================================
+ Hits 12122 12163 +41
- Misses 1367 1370 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
40e1403 to
1dd4291
Compare
- Add missing SHOULD requirement to specify the `escaping` value for 1.0.0 protocols. - Update `PrometheusSerializer` to be compliant with `escaping=underscores` when using OpenMetrics.
c3ebfae to
0ba8e0d
Compare
There was a problem hiding this comment.
Pull request overview
Updates the Prometheus exporters’ content negotiation and serialization to align with Prometheus/OpenMetrics “escaping” requirements, particularly escaping=underscores for OpenMetrics 1.0.0.
Changes:
- Emit
escaping=underscoresin OpenMetricsContent-Typeresponses and requireescaping=underscoreswhen anescapingparameter is explicitly provided inAccept. - Update serializer label/metric name handling to better match underscore-based escaping rules (including collapsing runs of invalid characters).
- Expand unit + fuzz + integration test coverage for the new behavior and update changelogs.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs | Adds coverage for label-key normalization differences between Prometheus vs OpenMetrics paths. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusMetricTests.cs | Adds OpenMetrics metric-name escaping/unit normalization test cases (leading digits, collapsing, unsupported chars). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs | Updates expected OpenMetrics Content-Type to include escaping=underscores. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHeadersParserTests.cs | Adds Accept header parsing test cases for escaping=underscores and rejects unsupported schemes. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.FuzzTests/PrometheusSerializerFuzzTests.cs | Splits fuzz coverage for Prometheus vs OpenMetrics label-key writers and updates reference implementations. |
| test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs | Updates Accept negotiation and Content-Type expectations for escaping parameter handling. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListener.cs | Emits OpenMetrics Content-Type with escaping=underscores. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs | Threads openMetricsRequested through tag writing so label-key escaping matches negotiated format. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializer.cs | Adds OpenMetrics-aware label-key writing and passes openMetricsRequested through label/tag/scope/target-info writers. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusMetric.cs | Introduces EscapeOpenMetricsName and adjusts OpenMetrics naming/unit suffix logic for underscore escaping. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusHeadersParser.cs | Extends HttpListener-side Accept parsing to validate escaping=underscores when present. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusCollectionManager.cs | Updates internal calls to serializer APIs that now require openMetricsRequested. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md | Documents escaping/serialization behavior changes. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs | Emits OpenMetrics Content-Type with escaping=underscores and validates escaping parameter in Accept. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md | Documents escaping/serialization behavior changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix missing prefixing for metrics that start with a digit.
Fix merge with main.
Update generator for label keys.
- Fix escaping behaviour for unit suffixes. - Fix incorrect label escaping for `:`.
|
Need to patch the fuzz tests. |
Update generator after changes in 2a588a0.
Builds on top of #7208.
Changes
escapingvalue for 1.0.0 protocols.PrometheusSerializerto be compliant withescaping=underscoreswhen using OpenMetrics.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)