Skip to content

exporter/prometheus: Expose scope name, version, schema URL and attributes as labels #40004

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

Merged
merged 4 commits into from
May 29, 2025

Conversation

ArthurSens
Copy link
Member

Description

This PR is a PoC for the spec change described at open-telemetry/opentelemetry-specification#4223

In the specification change, it's being proposed that Prometheus exporters stop generating the metric otel_scope_info with all the scope attributes and instead add all scope information as labels, turning Scope information "identifying".

Turns out our exporter never exposed otel_scope_info, so this PR just introduces the addition of the new labels.

@ArthurSens
Copy link
Member Author

I couldn't find an easy way of accessing SchemaURL, though. The current instrumentation scope used in the exporter doesn't include schema 🤔

@ArthurSens ArthurSens force-pushed the spec#4223-prom-exporter branch from affa338 to 289e54f Compare May 12, 2025 19:21
@mx-psi
Copy link
Member

mx-psi commented May 13, 2025

I couldn't find an easy way of accessing SchemaURL, though. The current instrumentation scope used in the exporter doesn't include schema 🤔

Instrumentation scope does not have a schema URL, the ScopeMetrics struct does https://pkg.go.dev/go.opentelemetry.io/collector/[email protected]/pmetric#ScopeMetrics.SchemaUrl

@jade-guiton-dd
Copy link
Contributor

jade-guiton-dd commented May 16, 2025

@mx-psi According to the spec the schema URL is part of the scope though (definition of instrumentation scope in the glossary). If it's meant to be separate like in the proto, we need to change the spec.

@mx-psi
Copy link
Member

mx-psi commented May 16, 2025

@mx-psi According to the spec the schema URL is part of the scope though (definition of instrumentation scope in the glossary). If it's meant to be separate like in the proto, we need to change the spec.

@jade-guiton-dd I don't think the spec requires the proto representation of the instrumentation scope to be all in a single field (at least I would say the glossary item you linked does not require that). I think the proto is weird but spec-compliant: you can still do a 1:1 association between the schema URL and the rest of the scope fields.

@jade-guiton-dd
Copy link
Contributor

jade-guiton-dd commented May 16, 2025

Ah sorry, I badly misinterpreted your comment (I thought you were suggesting we shouldn't expose the schema URL as part of the otel_scope_ labels because it's not semantically part of the scope). I agree that this is just a quirk of the proto, and we need to go get the SchemaUrl from the ScopeMetrics.

@ArthurSens ArthurSens force-pushed the spec#4223-prom-exporter branch 3 times, most recently from 29d5322 to d249acc Compare May 19, 2025 22:35
@ArthurSens ArthurSens force-pushed the spec#4223-prom-exporter branch from d249acc to 6e6f5ae Compare May 23, 2025 15:15
Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
@ArthurSens ArthurSens marked this pull request as ready for review May 23, 2025 15:25
@ArthurSens ArthurSens requested a review from a team as a code owner May 23, 2025 15:25
@ArthurSens ArthurSens changed the title exporter/prometheus: Expose scope name, version and attributes as labels exporter/prometheus: Expose scope name, version, schema URL and attributes as labels May 23, 2025

attrs := make([]string, 0, scopeAttributes.Len())
for k, v := range scopeAttributes.All() {
attrs = append(attrs, k+"*"+v.AsString())
Copy link
Contributor

Choose a reason for hiding this comment

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

since this uses the same delimiter * as attributes below, it seems possible for there to be a collision between timeseries where an attribute is a scope attribute in one, but a metric attribute in another.

}

func timeseriesSignature(ilmName string, metric pmetric.Metric, attributes pcommon.Map, resourceAttrs pcommon.Map) string {
func timeseriesSignature(scopeName string, scopeVersion string, scopeSchemaURL string, scopeAttributes pcommon.Map, metric pmetric.Metric, attributes pcommon.Map, resourceAttrs pcommon.Map) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't block this PR, but we are building massive strings to compute signatures here (contains all resource and metric attributes). That is probably using a huge amount of memory. We should strongly consider using something like internal/exp/metrics/identity.OfResourceMetric instead of computing large strings.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point, moving to the identity package would also solve the string collision problem. Would you be okay with me working on those in a follow-up PR? That way I don't need to solve the same problem twice :)

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, i'm OK with a follow-up

@ArthurSens ArthurSens added the ready to merge Code review completed; ready to merge by maintainers label May 29, 2025
@songy23 songy23 merged commit 69cc685 into open-telemetry:main May 29, 2025
177 checks passed
@github-actions github-actions bot added this to the next release milestone May 29, 2025
@ArthurSens ArthurSens deleted the spec#4223-prom-exporter branch May 29, 2025 22:28
github-merge-queue bot pushed a commit to open-telemetry/opentelemetry-specification that referenced this pull request Jun 5, 2025
Fixes
#4223

Prototypes:
- open-telemetry/opentelemetry-go#5947
- open-telemetry/opentelemetry-go#6770
- open-telemetry/opentelemetry-java#7356
-
open-telemetry/opentelemetry-collector-contrib#40060
-
open-telemetry/opentelemetry-collector-contrib#40004



## Changes

Currently (before this PR) [Prometheus and OpenMetrics
Compatibility](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md)
assumes that only scope name and scope version are identifying.

However, with
#4161
this is no longer true.

Therefore, this PR updates the Prometheus and OpenMetrics Compatibility
specification to add the scope name, version, schema URL, scope
attributes to all metrics.

This also removes the `otel_scope_info` as it looks that it won't be
useful. See:
#4223 (comment).

This change important for Collector
open-telemetry/opentelemetry-go#5846 (comment).
It is also is necessary towards stabilization of OTel-Prom/OpenMetrics
compatibility) and the Prometheus exporter.

_Initially, I thought about [splitting it into a few
PRs](#4223 (comment)).
However, it looks like doing it in one PR would be a more complete
approach (also there are not that many changes)._

---------

Co-authored-by: Jade Guiton <[email protected]>
Co-authored-by: Carlos Alberto Cortez <[email protected]>
github-merge-queue bot pushed a commit to open-telemetry/opentelemetry-specification that referenced this pull request Jun 5, 2025
Fixes
#4223

Prototypes:
- open-telemetry/opentelemetry-go#5947
- open-telemetry/opentelemetry-go#6770
- open-telemetry/opentelemetry-java#7356
-
open-telemetry/opentelemetry-collector-contrib#40060
-
open-telemetry/opentelemetry-collector-contrib#40004



## Changes

Currently (before this PR) [Prometheus and OpenMetrics
Compatibility](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md)
assumes that only scope name and scope version are identifying.

However, with
#4161
this is no longer true.

Therefore, this PR updates the Prometheus and OpenMetrics Compatibility
specification to add the scope name, version, schema URL, scope
attributes to all metrics.

This also removes the `otel_scope_info` as it looks that it won't be
useful. See:
#4223 (comment).

This change important for Collector
open-telemetry/opentelemetry-go#5846 (comment).
It is also is necessary towards stabilization of OTel-Prom/OpenMetrics
compatibility) and the Prometheus exporter.

_Initially, I thought about [splitting it into a few
PRs](#4223 (comment)).
However, it looks like doing it in one PR would be a more complete
approach (also there are not that many changes)._

---------

Co-authored-by: Jade Guiton <[email protected]>
Co-authored-by: Carlos Alberto Cortez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter/prometheus ready to merge Code review completed; ready to merge by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants