Limit exemplar label characters to conform to Prometheus limits#8362
Open
anuq wants to merge 6 commits into
Open
Limit exemplar label characters to conform to Prometheus limits#8362anuq wants to merge 6 commits into
anuq wants to merge 6 commits into
Conversation
6f05ab7 to
a0627db
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8362 +/- ##
============================================
+ Coverage 90.88% 90.91% +0.03%
- Complexity 7985 7990 +5
============================================
Files 898 898
Lines 24107 24123 +16
Branches 2406 2409 +3
============================================
+ Hits 21909 21932 +23
+ Misses 1455 1450 -5
+ Partials 743 741 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
psx95
reviewed
May 9, 2026
| private static int labelSetLength(Labels labels) { | ||
| int length = 0; | ||
| for (int i = 0; i < labels.size(); i++) { | ||
| length += labels.getName(i).length() + labels.getValue(i).length(); |
Contributor
There was a problem hiding this comment.
Looking at the OpenMetrics Exemplar spec, I think this function should be using codePointCount instead of length. This was also used in a previous PR addressing the same issue.
That PR already had reviews. Not sure if you've looked through that PR (it seems it has been inactive for a while now).
| assertThat(predicateCalledCount.get()).isEqualTo(2); | ||
| } | ||
|
|
||
| @Test |
Contributor
There was a problem hiding this comment.
Quick Question - would it be possible to convert these added unit tests into parameterized tests?
Addressed both suggestions: codePointCount instead of length() — Updated labelSetLength() to use String.codePointCount() so the limit is measured in Unicode code points, consistent with the OpenMetrics exemplar spec. (reference open-telemetry#6791) Parameterized tests — Consolidated the four exemplar label limit tests into a single @ParameterizedTest with @MethodSource, covering all four combinations (with/without span context × within/exceeding limit)
Addressed both suggestions: codePointCount instead of length() — Updated labelSetLength() to use String.codePointCount() so the limit is measured in Unicode code points, consistent with the OpenMetrics exemplar spec. (reference open-telemetry#6791) Parameterized tests — Consolidated the four exemplar label limit tests into a single @ParameterizedTest with @MethodSource, covering all four combinations (with/without span context × within/exceeding limit)
…github.com/anuq/opentelemetry-java into fix/prometheus-exemplar-label-length-limit # Conflicts: # exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverterTest.java
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 #6770
Limits exemplar label characters to Prometheus's 128 UTF-8 character maximum. When labels exceed this limit, filtered attributes are dropped while preserving trace_id and span_id for correlation.
Changes