Skip to content

Prometheus exporter: Stabilize Resource Constant Labels#5130

Open
ArthurSens wants to merge 2 commits into
open-telemetry:mainfrom
ArthurSens:prom-stabilize-resource-as-labels
Open

Prometheus exporter: Stabilize Resource Constant Labels#5130
ArthurSens wants to merge 2 commits into
open-telemetry:mainfrom
ArthurSens:prom-stabilize-resource-as-labels

Conversation

@ArthurSens

@ArthurSens ArthurSens commented Jun 3, 2026

Copy link
Copy Markdown
Member

Fixes #4987

Changes

Stabilize the configuration option for transforming OTLP Resource Attributes into Prometheus Labels.

The configuration option is currently available in the following SDKs:

  • Go SDK - API
  • Java SDK - API and Declarative config. Although names used for API and declarative config don't match the suggested name in the spec.
  • Javascript SDK - API
  • Rust SDK - API, although the name is slightly different from the one suggested in the spec.

Weird ones:

  • OTel Collector Prometheus exporter - has resource_to_telemetry_conversion, which has an "all or nothing" behavior; it doesn't allow the user to pick which ones to transform.
  • OTel Collector Prometheus remotewrite exporter - Similar to the one above, has a resource_to_telemetry_conversion with "all or nothing" behavior.

All other implementations do not provide this option yet


@jack-berg

Copy link
Copy Markdown
Member

Java SDK - API and Declarative config. Although names used for API and declarative config don't match the suggested name in the spec.

Fixed in open-telemetry/opentelemetry-java#8451

A Prometheus Exporter MAY offer configuration to add resource attributes as metric labels.
By default, it MUST NOT add any resource attributes as metric labels.
The configuration SHOULD allow the user to select resource attributes to include or exclude. Copied Resource attributes MUST NOT be
excluded from the `target_info` metric. The option SHOULD be named `resource_constant_labels`.

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.

the spec says the option should let users "include or exclude" resource attributes, but the name resource_constant_labels reads as an include-only list. And most languages already diverge...

The name doesn't fit the described behavior? Should we refine the name, or narrow the spec text to include-only before stabilizing or drop the SHOULD requirement about name completely from spec?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm failing to see how resource_constant_labels suggests an include-only list 🤔. Maybe the previous alternative (with_resource_constant_labels) could suggest something like this, but we got rid of it in #5084

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.

My bad- I meant to say the name resource_constant_labels does not convey if its include list or exclude list. And each language handles this in their own way. I think spec should avoid the SHOULD name the option as something wording, as the current word is not enough to convey if this is include/exlude list.

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.

And each language handles this in their own way

Check out how this is defined in declarative config: https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema-docs.md#experimentalprometheusmetricexporter-

Its an IncludeExclude type, which support arrays of glob pattern include / exclude. I think this works. Its sufficiently expressive, and this IncludeExclude glob pattern array pattern is used in other places in declarative config so it becomes a pattern users get familiar / comfortable with.

The spec could get really detailed and describe the exact semantics of declarative config, but then we end up writing the same thing in two places and having to keep them in sync and decide when they're out of sync enough to do something about. Given that the declarative config schema is an extension of the spec, and that we now have guidance to evolve spec related to config in lockstep with declarative config, I think practically speaking maintainers should look at both the spec and corresponding declarative config when defining their config APIs.

IMO, it fine for the spec to be more vague and defer to declarative config to do the heavy lifting of hashing out details.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting, Prometheus uses a string array that works as an exact match, not a glob pattern. And that's what I was aiming for in open-telemetry/opentelemetry-collector-contrib#48922

I'm not sure if we want to be explicit about the include/exclude strategy, but if we do then we might need to reword the text a bit

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.

Agree, we should let declarative config hashout details. Perhaps the easiest fix is to remove the normative "SHOULD be named" from spec wording completely. Spec states - this functionality must be offered. period.
IOW, "The option SHOULD be named resource_constant_labels." - this statement can be removed IMHO.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, I kinda like the idea of having consistency across all SDKs. Every config option adds to the cognitive load, so I believe it's easier for the end user if they don't need to learn all the different config options across different language SDKs that might or might not do the same thing.

That said, I'm not toooooo strongly opinionated here; if the majority of the group doesn't care about this, then I'm happy to drop it as well.

What are your thoughts @jack-berg, @open-telemetry/prometheus-interoperability?

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.

so I believe it's easier for the end user if they don't need to learn all the different config options across different language SDKs that might or might not do the same thing.

That's what declarative config does. Its the language agnostic configuration interface. Semantics of all types and properties are laid out explicitly, often in more detail than the spec.

I think its fine as is, but would also think it were fine if the spec was more explicit like declarative config is. 🤷

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.

I think named parameters in the spec is usually a good thing. I'm open to other names if we don't like the current one. I'm happy with the current state

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@ArthurSens
ArthurSens force-pushed the prom-stabilize-resource-as-labels branch from a750021 to 2c30c5a Compare June 25, 2026 18:33
@ArthurSens
ArthurSens requested a review from a team as a code owner June 25, 2026 18:33
@github-actions

Copy link
Copy Markdown

This PR was marked stale. It will be closed in 14 days without additional activity.

@github-actions github-actions Bot added the Stale label Jul 10, 2026
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.

Stabilize Prometheus Metrics Exporter spec: Resource Attributes configuration

6 participants