Skip to content

[receiver/prometheus] Generate Scope Attributes from otel_scope_<attribute-name> labels#46612

Merged
atoulme merged 13 commits into
open-telemetry:mainfrom
ArthurSens:scope-attribute-labels
Mar 30, 2026
Merged

[receiver/prometheus] Generate Scope Attributes from otel_scope_<attribute-name> labels#46612
atoulme merged 13 commits into
open-telemetry:mainfrom
ArthurSens:scope-attribute-labels

Conversation

@ArthurSens
Copy link
Copy Markdown
Member

Description

Add support for extracting scope attributes from otel_scope_ labels on metrics in the Prometheus receiver, per the spec change.
This is gated behind receiver.prometheusreceiver.UseScopeAttributeLabels (alpha, disabled by default). The gate acts as a switch:

  • Disabled (default): existing behavior — scope attributes come from otel_scope_info, and otel_scope_ labels are treated as regular data point attributes.
  • Enabled: scope attributes are read from otel_scope_ labels on every metric, otel_scope_info is ignored.

Link to tracking issue

Fixes #41502

Testing

  • Added integration tests (TestScopeAttributeLabelsFeatureGate) covering both gate states: enabled extracts scope attributes and splits scopes; disabled preserves otel_scope_* as regular labels.
  • Existing TestScopeInfoScopeAttributes and all internal tests pass unchanged.

Comment thread pkg/translator/prometheus/constants.go Outdated
Comment thread receiver/prometheusreceiver/internal/transaction.go Outdated
Comment thread receiver/prometheusreceiver/internal/metricfamily.go
Comment thread receiver/prometheusreceiver/internal/transaction.go
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Scope attributes are always extracted from `otel_scope_<attribute-name>` labels on metrics.
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.

Isn't it also true now that we drop any extra scope attributes from the resulting attributes? Which is a breaking change if somebody relied on them?

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 not sure what you mean here. Could you elaborate?

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.

Add something like "labels starting with otel_scope_" are no longer included as metric attributes, and are put in scope attributes instead"

name string
version string
schemaURL string
attrsHash uint64
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'm not sure about the cardinality of scopes , but you can run into conflicts with hashes.
Since we sort attributes (I think), maybe it would be better to just make a concatenated copy of the scope attributes here using some non utf-8 delimeter ?

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.

Yeah, I tried that, but it has a big performance penalty. Building the string adds 10-15% to allocs and seconds/op for the whole Append method.

I don't understand hash collision well enough to say this penalty is worth it for better reliability, though 😅

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 we use hashes all over the place in the receiver. From my testing with the otel-go SDK, collisions aren't remotely likely until you get into the ~10 billion cardinality range for the cache.

If we want to revisit this, lets do it outside of this PR.

Comment thread receiver/prometheusreceiver/internal/util.go Outdated
base := getSortedNotUsefulLabels(mType)
exclusions := make([]string, 0, len(base)+ls.Len())
exclusions = append(exclusions, base...)
seen := make(map[string]struct{}, len(base))
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.

How frequently do we call this function? Isn't this an extra allocation for every sample? Could we add a benchmark ?

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.

Yes, good catch. I'm adding a commit so we only allocate exclusions if we find a label prefixed with otel_scope_, otherwise we just return base.

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.

Regarding the benchmark, we already have a testbed. I can run it if you feel like this really needs to be properly benchmarked :)

@ArthurSens ArthurSens force-pushed the scope-attribute-labels branch from aa64109 to 7b6c049 Compare March 16, 2026 20:48
@ArthurSens
Copy link
Copy Markdown
Member Author

ArthurSens commented Mar 16, 2026

I went through your feedback @krajorama, but couldn't find the time to address everything. I'll let you know once all comments have been addressed!

@ArthurSens ArthurSens force-pushed the scope-attribute-labels branch from a9da81f to c3b016e Compare March 17, 2026 20:29
@ArthurSens
Copy link
Copy Markdown
Member Author

This should be ready for another round of reviews @krajorama @dashpole :)

Comment thread receiver/prometheusreceiver/internal/transaction.go Outdated
Comment thread receiver/prometheusreceiver/internal/transaction.go Outdated
@ArthurSens ArthurSens force-pushed the scope-attribute-labels branch from 2b0dc35 to cafa4ff Compare March 27, 2026 21:47
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@ArthurSens ArthurSens force-pushed the scope-attribute-labels branch from cafa4ff to 2b45ea6 Compare March 30, 2026 17:34
@ArthurSens ArthurSens added the ready to merge Code review completed; ready to merge by maintainers label Mar 30, 2026
@atoulme atoulme merged commit 12a1810 into open-telemetry:main Mar 30, 2026
208 checks passed
pull Bot pushed a commit to CodeWeaver13/opentelemetry-specification that referenced this pull request Apr 27, 2026
…etry#5004)

Fixes open-telemetry#4752

## Changes

Stabilizes the conversion of labels prefixed with `otel_scope_` to OTLP
Instrumentation scope. Implementation has been done in
open-telemetry/opentelemetry-collector-contrib#46612

For non-trivial changes, follow the [change proposal
process](https://github.com/open-telemetry/opentelemetry-specification/blob/main/CONTRIBUTING.md#proposing-a-change).

* [X] Related issues open-telemetry#4752 
* [ ] Related [OTEP(s)](https://github.com/open-telemetry/oteps) #
* [ ] Links to the prototypes (when adding or changing features)
* [X]
[`CHANGELOG.md`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/CHANGELOG.md)
file updated for non-trivial changes
* For trivial changes, include `[chore]` in the PR title to skip the
changelog check
* [ ] [Spec compliance
matrix](https://github.com/open-telemetry/opentelemetry-specification/blob/main/spec-compliance-matrix/template.yaml)
updated if necessary

---------

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Co-authored-by: David Ashpole <dashpole@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg/translator/prometheus ready to merge Code review completed; ready to merge by maintainers receiver/prometheus Prometheus receiver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[receiver/prometheus] Add support for otel_scope_<attribute-name> labels

6 participants