feat(metrics): Implement exemplar metrics - #239
Draft
ethanolchik wants to merge 29 commits into
Draft
Conversation
Add owned fixed-bucket storage, direct protobuf encoding, and support for the legacy HistogramBuilder API (only classic histograms in this commit).
Choose to pre-sort histogram buckets over a sorted boolean variable. Also satisfies cargo clippy & cargo fmt
ethanolchik
force-pushed
the
metrics/exemplar-metrics
branch
from
July 24, 2026 14:43
364b7a6 to
723b5a3
Compare
…omplete, non-empty names
… names Legacy metric and label names must match Prometheus' name grammars. Names outside these grammars cause Prometheus to reject the scrape, and the grammars exclude non-ASCII characters. Foundations now quotes label names and uses OpenMetrics' quoted metric-name syntax when required. This allows UTF-8 and other nonstandard names without affecting legacy compatibility.
Add registerable counter, classic histogram, and native histogram types that retain exemplars alongside observations. Support typed and legacy label sets, Family usage, OpenMetrics text, and Prometheus protobuf encoding. Validate exemplars during collection and report serialisation failures as non-fatal diagnostics.
ethanolchik
force-pushed
the
metrics/exemplar-metrics
branch
from
July 27, 2026 16:55
723b5a3 to
ea4b084
Compare
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.
Overview
Adds first-party exemplar-aware metric types for counters, classic histograms, and native histograms while leaving existing metric types unchanged.
Public API
CounterWithExemplarHistogramWithExemplarsNativeHistogramWithExemplarsExemplaraccessors for labels and sampled values are exposed throughCounterWithExemplar::get.These types integrate with
Family, registration, collection, and the existing protobuf and OpenMetrics encoders.Recording Semantics
Recording does not require exemplar labels to implement
Serialize; serialisation occurs when the metric is encoded.Encoding
Counter and classic-histogram exemplars are emitted in both protobuf and OpenMetrics text.
Native-histogram exemplars:
Empty counter and classic-histogram exemplar label sets remain valid and are emitted in text as {}.
Labels And Validation
Exemplar labels use the existing label serialiser and support:
Invalid, duplicate, or unserialisable exemplar labels drop only the exemplar. The metric sample remains available, and a non-fatal diagnostic is emitted.
Native-histogram exemplars without the required timestamp are removed with a non-fatal diagnostic; the native histogram itself is still emitted.