Skip to content

Prometheus exporter: Clarify interation between content negotiation and translation strategy#5134

Open
ArthurSens wants to merge 3 commits into
open-telemetry:mainfrom
ArthurSens:fix5062
Open

Prometheus exporter: Clarify interation between content negotiation and translation strategy#5134
ArthurSens wants to merge 3 commits into
open-telemetry:mainfrom
ArthurSens:fix5062

Conversation

@ArthurSens

Copy link
Copy Markdown
Member

Fixes #5062

Changes

…nd translation strategy

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@ArthurSens ArthurSens requested review from a team as code owners June 5, 2026 18:21
@ArthurSens ArthurSens added the Skip Changelog Label to skip the changelog check label Jun 5, 2026
@ArthurSens

Copy link
Copy Markdown
Member Author

cc @open-telemetry/prometheus-interoperability


- If configured with `NoTranslation` but the client requests `escaping=underscores`, the exporter MUST apply underscore escaping.
- If configured with `UnderscoreEscapingWithSuffixes` but the client requests `escaping=allow-utf8`, there's no need to revert what has been translated since the exporter will continue to be compliant.
- If configured with `UnderscoreEscapingWithSuffixes` but the client requests `escaping=allow-utf-8`, there's no need to revert what has been translated since the exporter will continue to be compliant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zeitlinger does this align with what you've been working on in open-telemetry/opentelemetry-java#8346?

What are the conditions that would allow a client to actually see metrics conforming to the configured translation strategy? Does a client essentially have to set escaping=allow-utf-8 to avoid the prometheus client library undoing the translation strategy?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zeitlinger does this align with what you've been working on in open-telemetry/opentelemetry-java#8346?

yes it does

What are the conditions that would allow a client to actually see metrics conforming to the configured translation strategy? Does a client essentially have to set escaping=allow-utf-8 to avoid the prometheus client library undoing the translation strategy?

yes

@quentinmit quentinmit Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should augment the examples list with all the combinations of translation and header. For example, something like

Examples:
For a counter metric named `foo.bar`:
- With `escaping=underscores` or no `Accept` header (Prometheus's default behavior in Prometheus 2.x):
  - If configured with `UnderscoreEscapingWithSuffixes` (default), the metric will be named `foo_bar_total`
  - If configured with `UnderscoreEscapingWithoutSuffixes`, the metric will be named `foo_bar`
  - If configured with `NoUTF8EscapingWithSuffixes`, the metric will be named `foo_bar_total`
  - if configured with `NoTranslation`, the metric will be named `foo_bar`
- With `escaping=allow-utf-8` (Prometheus's default behavior in Prometheus 3.x):
  - If configured with `UnderscoreEscapingWithSuffixes` (default), the metric will be named `foo_bar_total`
  - If configured with `UnderscoreEscapingWithoutSuffixes`, the metric will be named `foo_bar`
  - If configured with `NoUTF8EscapingWithSuffixes`, the metric will be named `foo.bar_total`
  - if configured with `NoTranslation`, the metric will be named `foo.bar`

I think I have all of those combinations correct. There is no value for translation_strategy that will result in Prometheus 2.x seeing foo_bar_total and Prometheus 3.x seeing foo.bar.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would do it as a table - but yes, would be great to have this explicit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, the combinations are correct IMO

Comment on lines +179 to +181
When a Prometheus Exporter is configured with a permissive `translation_strategy`,
such as `NoTranslation`, the final output format and character escaping MUST
comply with the content negotiation's restrictions based on the `Accept` header.

@quentinmit quentinmit Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think it should just explicitly say that content negotiation happens after translation. Something like:

First, `translation_strategy` MUST be applied to construct metric names. Then,
the Prometheus exporter MUST apply content negotiation, which can include
a second translation of metric names.


- If configured with `NoTranslation` but the client requests `escaping=underscores`, the exporter MUST apply underscore escaping.
- If configured with `UnderscoreEscapingWithSuffixes` but the client requests `escaping=allow-utf8`, there's no need to revert what has been translated since the exporter will continue to be compliant.
- If configured with `UnderscoreEscapingWithSuffixes` but the client requests `escaping=allow-utf-8`, there's no need to revert what has been translated since the exporter will continue to be compliant.

@quentinmit quentinmit Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should augment the examples list with all the combinations of translation and header. For example, something like

Examples:
For a counter metric named `foo.bar`:
- With `escaping=underscores` or no `Accept` header (Prometheus's default behavior in Prometheus 2.x):
  - If configured with `UnderscoreEscapingWithSuffixes` (default), the metric will be named `foo_bar_total`
  - If configured with `UnderscoreEscapingWithoutSuffixes`, the metric will be named `foo_bar`
  - If configured with `NoUTF8EscapingWithSuffixes`, the metric will be named `foo_bar_total`
  - if configured with `NoTranslation`, the metric will be named `foo_bar`
- With `escaping=allow-utf-8` (Prometheus's default behavior in Prometheus 3.x):
  - If configured with `UnderscoreEscapingWithSuffixes` (default), the metric will be named `foo_bar_total`
  - If configured with `UnderscoreEscapingWithoutSuffixes`, the metric will be named `foo_bar`
  - If configured with `NoUTF8EscapingWithSuffixes`, the metric will be named `foo.bar_total`
  - if configured with `NoTranslation`, the metric will be named `foo.bar`

I think I have all of those combinations correct. There is no value for translation_strategy that will result in Prometheus 2.x seeing foo_bar_total and Prometheus 3.x seeing foo.bar.

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@ArthurSens ArthurSens requested a review from a team as a code owner June 16, 2026 12:41
@ArthurSens ArthurSens requested review from Copilot, dashpole, jack-berg, quentinmit and zeitlinger and removed request for quentinmit and zeitlinger June 16, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Clarifies how a Prometheus Exporter’s translation_strategy interacts with Prometheus content negotiation, especially when the configured strategy is permissive and may need additional escaping based on the client’s Accept header.

Changes:

  • Replaces example bullets with a step-by-step description of applying translation_strategy first, then applying content negotiation (including potentially a second escaping step).
  • Adds a concrete example table mapping translation_strategy and requested escaping scheme to resulting metric names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread specification/metrics/sdk_exporters/prometheus.md
Comment thread specification/metrics/sdk_exporters/prometheus.md Outdated
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog Label to skip the changelog check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[prometheus] Content Negotiation spec is inconsistent with Translation Strategy spec

6 participants