[Exporter.Prometheus] Add allow-utf-8 escaping#7440
Merged
Conversation
Add missing `in` modifiers on methods accepting parameters of type `PrometheusProtocol`.
Add support for the `dots` and `values` escaping schemes. Contributes to open-telemetry#7246.
Fix incorrectly sorted `[InlineData]` attributes.
- Update comments. - Add `Debug.Assert()`. - Add PR number to CHANGELOGs.
- Add missing coverage. - Remove unused code.
Add additional interesting test cases taken from https://github.com/prometheus/common/blob/43de10cc658055c6b5e4d619edc917d5af493409/model/metric_test.go.
Add support for the `allow-utf-8` escaping scheme. Fixes open-telemetry#7246.
martincostello
commented
Jun 21, 2026
martincostello
commented
Jun 21, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7440 +/- ##
==========================================
+ Coverage 90.12% 90.41% +0.28%
==========================================
Files 285 281 -4
Lines 15343 15414 +71
==========================================
+ Hits 13828 13936 +108
+ Misses 1515 1478 -37
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Add PR number.
Add missing test coverage.
Add a new benchmark that compares the different text formats and escaping schemes.
Avoid allocations when a label does not need to be sanitized.
Make lines less long.
Further avoid allocations when writing labels.
Move entries to the right place.
Update comments.
4 tasks
This was referenced Jul 18, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7246
Changes
Add support for the
allow-utf-8escaping scheme.Benchmark Results
Summary (generated by Claude 🐙)
Prometheus serializer allocation improvements (this branch vs
gh-7246)PrometheusSerializerBenchmarks(Prometheus text v1.0.0 / underscores), BenchmarkDotNet Default job + memory diagnoser, .NET 10.0.9, i7-13700H. Both refs benchmarked in the same session (gh-7246from a fresh worktree; this branch = allow-utf-8 + label-key allocation optimizations). Allocation normalised to KB per single op.gh-7246Allocation scales linearly across the 1 / 1000 / 10000 call-count params, confirming the per-op figures.
Summary: allocation is down 13–37% in core serialization with neutral-to-faster throughput (StdDevs ~1% this run). The reduction comes from no longer allocating a
StringBuilder+ string for every output label key — already-valid keys are now returned/written with zero allocation. The allow-utf-8 feature itself is allocation-neutral on the common path.Detailed Results
Expand to view
#7439
This PR
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)