Skip to content

Support Prometheus translation_strategy configuration #8195

@zeitlinger

Description

@zeitlinger

Summary

Implement the translation_strategy configuration option for the Prometheus exporter.

This controls how OTel metric/label names are translated to Prometheus format and whether type/unit suffixes are appended. The converter becomes the single authority for suffix decisions — the OM2 format writer renders names as-is (no smart-append).

Strategies

Strategy Escaping expositionBaseName Labels __ collapse
UnderscoreEscapingWithSuffixes (default) prometheusName() base + unit + type suffix (_total, _info) prometheusName() yes
UnderscoreEscapingWithoutSuffixes prometheusName() base only prometheusName() yes
NoUTF8EscapingWithSuffixes passthrough base + unit + type suffix passthrough no
NoTranslation passthrough raw OTel name (via originalName) passthrough no

Key design decision: the converter uses the 4-arg MetricMetadata(name, expositionBaseName, help, unit) constructor to explicitly control what the OM2 writer outputs. sanitizeMetricName() is no longer called (it's a no-op in prom_client_java 1.6+).

Changes required

  1. Otel2PrometheusConverter — branch convertMetadata() and convertLabelName() on strategy. Type-aware suffix logic (append _total for counters, _info for info metrics) moves into the converter.
  2. PrometheusMetricReaderBuilder — add setTranslationStrategy(TranslationStrategy)
  3. PrometheusHttpServerBuilder — delegate to reader builder
  4. PrometheusComponentProvider (DC) — wire translation_strategy from config model (enum already exists in generated schema)
  5. No env var / system property — DC only, per spec

Dependencies

The NoUTF8EscapingWithSuffixes and NoTranslation strategies depend on prometheus/client_java scrape-time-suffix-handling branch which adds originalName, expositionBaseName, and scrape-time suffix handling. The implementation PR will be a draft until the next prom_client_java release includes these changes.

Previous work

  • #7588 — earlier attempt with a utf8 flag, closed in favor of translation_strategy
  • #8080 — updated prom client to 1.5.0 with backward-compatible escaping

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions