Skip to content

Prometheus translation modes and content negotiation #4533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ArthurSens
Copy link
Member

Related to #4494

Changes

This change focuses on three things:

  • Flexibilization of underscore scaping
  • Flexibilization of unit and type suffix additions
  • Add content negotiation

The goal is to mimic Prometheus' existing configuration that controls the translation of metric names when receiving OTLP metrics via its /otlp endpoint. Configuration alignment will help users migrate in both directions (Prometheus/Collector) when switching their metrics collection systems.

Additional Information

Some further reading might be helpful for reviewers:


in the metric name MUST be replaced with the `_` character. Multiple
consecutive `_` characters MUST be replaced with a single `_` character.
[Prometheus Metric Name](https://prometheus.io/docs/instrumenting/exposition_formats/#comments-help-text-and-type-information).
Prometheus naming conventions require metric names to match the regex: `[a-zA-Z_:]([a-zA-Z0-9_:])*`. Invalid characters
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Prometheus naming conventions require metric names to match the regex: `[a-zA-Z_:]([a-zA-Z0-9_:])*`. Invalid characters
Prometheus naming conventions encourage metric names to match the regex: `[a-zA-Z_:]([a-zA-Z0-9_:])*`. Discouraged characters

consecutive `_` characters MUST be replaced with a single `_` character.
[Prometheus Metric Name](https://prometheus.io/docs/instrumenting/exposition_formats/#comments-help-text-and-type-information).
Prometheus naming conventions require metric names to match the regex: `[a-zA-Z_:]([a-zA-Z0-9_:])*`. Invalid characters
in the metric name SHOULD be replaced with the `_` character, aiming for compatibility with Prometheus conventions. Multiple
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
in the metric name SHOULD be replaced with the `_` character, aiming for compatibility with Prometheus conventions. Multiple
in the metric name SHOULD be replaced with the `_` character by default, aiming for compatibility with Prometheus conventions. Multiple

[Prometheus Metric Name](https://prometheus.io/docs/instrumenting/exposition_formats/#comments-help-text-and-type-information).
Prometheus naming conventions require metric names to match the regex: `[a-zA-Z_:]([a-zA-Z0-9_:])*`. Invalid characters
in the metric name SHOULD be replaced with the `_` character, aiming for compatibility with Prometheus conventions. Multiple
consecutive `_` characters SHOULD be replaced with a single `_` character.
Copy link
Contributor

Choose a reason for hiding this comment

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

@ywwg do we want to keep this in the spec? Is this what the prometheus/common escaping library does?

Copy link

Choose a reason for hiding this comment

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

I believe this is not what the prom/common escaping library does, but it's important to note that that code is newer and may not actually be correct. I think the best option is to figure out what Most People Are Doing and write the spec to match that

Copy link

Choose a reason for hiding this comment

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

and as a suffix to the metric name unless the metric name already ends with the
unit (before type-specific suffixes), or the unit metadata MUST be omitted. The
[UNIT metadata](https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md#metricfamily).
A suffix to the metric name MAY be added unless the metric name already ends with the
Copy link
Contributor

Choose a reason for hiding this comment

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

Given we are doing escaping by default above, should we make this a SHOULD? Or
"SHOULD, by default,"?

Copy link

Choose a reason for hiding this comment

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

I agree, in general the vibe of the spec is that people SHOULD do these things, but MAY do something else.

Comment on lines +69 to +71
- `UnderscoreEscapingWithSuffixes`, the default. This fully escapes metric names for classic Prometheus metric name compatibility, and includes appending type and unit suffixes.
- `NoUTF8EscapingWithSuffixes` will disable changing special characters to `_`. Special suffixes like units and `_total` for counters will be attached.
- `NoTranslation`. This strategy bypasses all metric and label name translation, passing them through unaltered.
Copy link

Choose a reason for hiding this comment

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

Prometheus already also has UTF8 with suffixes, we should list that here for permutation completeness

A Prometheus Exporter MAY support a configuration option to produce metrics without a [unit suffix](../../compatibility/prometheus_and_openmetrics.md#metric-metadata)
or UNIT metadata. The option MAY be named `without_units`, and MUST be `false` by default.
A Prometheus Exporter MAY support a configuration option that controls the translation of metric names from OpenTelemetry Naming Conventions to [Prometheus Naming conventions](https://prometheus.io/docs/practices/naming/).
If the Prometheus exporter supports such configuration it MUST be named `translation_strategy`, and the translation options MUST be:
Copy link

Choose a reason for hiding this comment

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

I don't think we should enforce the configuration name with MUST, esp because the without_units configuration option MAY be named that as indicated below.

Comment on lines +102 to +105
- `allow-utf8` - Allow UTF-8 characters in metric and label names
- `underscores` - Replace invalid characters with underscores
- `dots` - Replace invalid characters with dots
- `values` - Escape invalid characters in values only
Copy link

Choose a reason for hiding this comment

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

Suggested change
- `allow-utf8` - Allow UTF-8 characters in metric and label names
- `underscores` - Replace invalid characters with underscores
- `dots` - Replace invalid characters with dots
- `values` - Escape invalid characters in values only
- `allow-utf8` - Allow UTF-8 characters in metric and label names
- `underscores` - Replace invalid characters with underscores
- `dots` - Replace dots with `_dot_` and invalid characters with underscores
- `values` - Escape invalid characters with UTF-8 code points as defined in: https://github.com/prometheus/docs/blob/main/docs/instrumenting/escaping_schemes.md#value-encoding-escaping-values

Copy link

Choose a reason for hiding this comment

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

or some other summary of the correct escaping schemes

For example:

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

Choose a reason for hiding this comment

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

love this clarification!

@ArthurSens ArthurSens marked this pull request as ready for review June 11, 2025 13:03
@ArthurSens ArthurSens requested review from a team as code owners June 11, 2025 13:03
@ArthurSens
Copy link
Member Author

Folks, I'm out until June 25th. @ywwg is picking this up while I'm gone :)

I've removed the draft mode to help Owen with his notification settings

Copy link

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jun 19, 2025
@ywwg
Copy link

ywwg commented Jun 20, 2025

not stale

@ywwg
Copy link

ywwg commented Jun 20, 2025

(it won't let me remove the stale label)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants