Skip to content

Add Prometheus translation strategy support#8346

Draft
zeitlinger wants to merge 4 commits intoopen-telemetry:mainfrom
zeitlinger:codex/prometheus-translation-strategy
Draft

Add Prometheus translation strategy support#8346
zeitlinger wants to merge 4 commits intoopen-telemetry:mainfrom
zeitlinger:codex/prometheus-translation-strategy

Conversation

@zeitlinger
Copy link
Copy Markdown
Member

@zeitlinger zeitlinger commented Apr 29, 2026

Summary

  • add TranslationStrategy support to the Prometheus exporter builder and declarative config
  • upgrade Prometheus client_java to 1.6.1, which provides the released naming support this needs
  • preserve existing content negotiation behavior, while enabling non-default strategies to use OM2 name-preservation semantics
  • align underscore-escaping label-name normalization with the OTel Prometheus compatibility rules / prometheus/otlptranslator behavior for invalid characters, repeated underscores, and digit-leading labels

Notes

  • For non-default translation strategies, this intentionally uses only OM2 name-preservation semantics.
  • No other OM2 features are enabled.
  • Content negotiation remains unchanged, so OpenMetrics responses still use the legacy OM1 content type by design.
  • The behavior change from the new Prometheus release is that metric names can now be passed through as-is for the relevant strategies.
  • prometheus/otlptranslator preserves labels normalized to __...__; Prometheus Java rejects user labels starting with __, so those labels are collapsed to a valid single-underscore form instead.

Test plan

  • ./gradlew :exporters:prometheus:test --tests io.opentelemetry.exporter.prometheus.PrometheusHttpServerTest.fetchOpenMetrics --tests io.opentelemetry.exporter.prometheus.PrometheusHttpServerTest.fetchOpenMetrics_translationStrategyEnablesOm2 --tests io.opentelemetry.exporter.prometheus.PrometheusMetricReaderTest --tests io.opentelemetry.exporter.prometheus.Otel2PrometheusConverterTest --tests io.opentelemetry.exporter.prometheus.internal.PrometheusMetricReaderProviderTest :sdk-extensions:declarative-config:test --tests io.opentelemetry.sdk.autoconfigure.declarativeconfig.MetricReaderFactoryTest.create_PullPrometheusConfigured

Resolves #8195

Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 88.11881% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.29%. Comparing base (df8063b) to head (2cc649c).

Files with missing lines Patch % Lines
.../exporter/prometheus/Otel2PrometheusConverter.java 90.00% 2 Missing and 3 partials ⚠️
...ometheus/internal/PrometheusComponentProvider.java 55.55% 3 Missing and 1 partial ⚠️
...try/exporter/prometheus/PrometheusUnitsHelper.java 85.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8346      +/-   ##
============================================
- Coverage     90.31%   90.29%   -0.03%     
- Complexity     7725     7762      +37     
============================================
  Files           850      851       +1     
  Lines         23259    23352      +93     
  Branches       2364     2377      +13     
============================================
+ Hits          21007    21085      +78     
- Misses         1528     1537       +9     
- Partials        724      730       +6     

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

Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.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.

Support Prometheus translation_strategy configuration

1 participant