Skip to content

Limit exemplar label characters to conform to Prometheus limits#8362

Open
anuq wants to merge 9 commits into
open-telemetry:mainfrom
anuq:fix/prometheus-exemplar-label-length-limit
Open

Limit exemplar label characters to conform to Prometheus limits#8362
anuq wants to merge 9 commits into
open-telemetry:mainfrom
anuq:fix/prometheus-exemplar-label-length-limit

Conversation

@anuq
Copy link
Copy Markdown
Contributor

@anuq anuq commented May 2, 2026

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

  • Added EXEMPLAR_MAX_LABEL_SET_LENGTH constant (128 chars)
  • Modified convertExemplar() to check label set length and drop attributes if needed
  • Added helper method labelSetLength() to calculate total label character count
  • Added comprehensive tests for both within-limit and exceeding-limit scenarios

@anuq anuq requested a review from a team as a code owner May 2, 2026 13:15
@anuq anuq force-pushed the fix/prometheus-exemplar-label-length-limit branch from 6f05ab7 to a0627db Compare May 2, 2026 14:46
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.99%. Comparing base (8bacccc) to head (4e76406).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8362      +/-   ##
============================================
- Coverage     91.15%   90.99%   -0.16%     
- Complexity     7763     7814      +51     
============================================
  Files           881      892      +11     
  Lines         23409    23718     +309     
  Branches       2331     2364      +33     
============================================
+ Hits          21338    21582     +244     
- Misses         1376     1416      +40     
- Partials        695      720      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This was referenced May 4, 2026
anuq added 4 commits May 15, 2026 21:43
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
anuq added 2 commits May 23, 2026 14:56
- Refactor exemplarLabelLimit test to use Named arguments and consistent naming
- Replace unused String testName parameter with Named.of() for better test display
- Rename "short" attribute key to "short_attr" for consistency with "long_attr"
Copy link
Copy Markdown
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit on EXEMPLAR_MAX_LABEL_SET_LENGTH visibility.

Thanks!

…rometheus/Otel2PrometheusConverter.java


review comment fix

Co-authored-by: Jack Berg <34418638+jack-berg@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Limit prometheus exemplar label characters to conform to prometheus limits

3 participants