Skip to content

Limit exemplar label characters to conform to Prometheus limits#8362

Open
anuq wants to merge 8 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 8 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 91.18%. Comparing base (8bacccc) to head (fe8b17b).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8362      +/-   ##
============================================
+ Coverage     91.15%   91.18%   +0.02%     
- Complexity     7763     7768       +5     
============================================
  Files           881      881              
  Lines         23409    23425      +16     
  Branches       2331     2334       +3     
============================================
+ Hits          21338    21359      +21     
+ Misses         1376     1372       -4     
+ Partials        695      694       -1     

☔ 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"
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

2 participants