Skip to content

[receiver/prometheus] Drop __ labels from datapoint attributes - #52623

Closed
dashpole wants to merge 3 commits into
open-telemetry:mainfrom
dashpole:drop-internal-prometheus-labels
Closed

dashpole wants to merge 3 commits into
open-telemetry:mainfrom
dashpole:drop-internal-prometheus-labels

Conversation

@dashpole

@dashpole dashpole commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description:
Update the prometheus receiver to dynamically exclude any internal label starting with __ from being added as OTLP datapoint attributes, rather than relying on a hardcoded list of internal labels (such as model.SchemeLabel, model.MetricsPathLabel, etc.).

This allows the receiver to properly exclude all standard internal prometheus labels that may be present during translation, as opposed to only a limited subset.

Testing:
Added unit and benchmark allocation regression tests in metricfamily_test.go and transaction_test.go verifying internal __ label exclusion and zero-allocation series ref hashing.

@dashpole
dashpole requested a balanced review from Copilot November 2, 2026 19:08

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Closed · refreshed 2026-11-04 15:22 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@dashpole
dashpole force-pushed the drop-internal-prometheus-labels branch from aa1fa4f to 61cb319 Compare November 2, 2026 19:11
Update prometheus receiver to dynamically exclude any internal label starting with `__` from being added as OTLP datapoint attributes, rather than relying on a hardcoded list of internal labels.
Restore __name__, __scheme__, and __metrics_path__ to notUsefulLabelsOther and add isExtraInternalLabel so standard scraped series avoid allocating per-series exclusion slices, add unit and allocation regression tests, and trim changelog subtext.
@dashpole dashpole changed the title [prometheusreceiver] drop __ labels from datapoint attributes [receiver/prometheus] Drop __ labels from datapoint attributes Nov 3, 2026

@krajorama krajorama left a comment

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 this at all, see comment.

@@ -491,6 +491,10 @@ func getScopeID(ls labels.Labels) (scopeID, pcommon.Map, bool) {
var attrs pcommon.Map
var hasAttrs, hasScopeLabels bool
ls.Range(func(lbl labels.Label) {
if isExtraInternalLabel(lbl.Name) {
hasScopeLabels = true

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.

nit the hasScopeLabels variable name is now misleading everywhere, I'm not sure what I'd name this

@@ -491,6 +491,10 @@ func getScopeID(ls labels.Labels) (scopeID, pcommon.Map, bool) {
var attrs pcommon.Map
var hasAttrs, hasScopeLabels bool
ls.Range(func(lbl labels.Label) {
if isExtraInternalLabel(lbl.Name) {
hasScopeLabels = true
return

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.

Does this mean that if two series only differed in a reserved (__.*) label , they would now make those series conflict? That could lead to some unexpected results - and it's breaking change.

I think we should just log a warning if we see such label, but not enforce Prometheus rules that Prometheus itself doesn't enforce. AFAIK Prometheus will happily scrape or add during metric relabelling reserved names, so making this change would not let the collector be a drop in replacement for Prometheus.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right — Prometheus strips __* labels from target labels in Target.LabelsRange, but preserves any __* labels exposed by the target or added via metric_relabel_configs. Closing this in favor of #52736.

@dashpole dashpole closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

receiver/prometheus Prometheus receiver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants