Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

opentelemetry-exporter-prometheus: handle metric metadata collisions - #5927

Open
dashpole wants to merge 2 commits into
open-telemetry:mainfrom
dashpole:prometheus-metric-metadata-collisions
Open

dashpole wants to merge 2 commits into
open-telemetry:mainfrom
dashpole:prometheus-metric-metadata-collisions

Conversation

@dashpole

Copy link
Copy Markdown
Contributor

Description

Implements the OpenTelemetry Prometheus Metric Metadata conflict specification in opentelemetry-exporter-prometheus:

  • Resolve the canonical Prometheus metric name up front (_resolve_prometheus_name) and accumulate data points across all instruments/scopes and queued MetricsData payloads in _PendingMetricFamily before building each prometheus_client metric family once per scrape with unified sorted label keys ("" backfilled for missing labels).
  • Drop conflicting metrics and log a warning when two metrics resolve to the same Prometheus metric name with conflicting TYPEs (e.g. counter foo vs gauge foo_total, or gauge vs histogram).
  • Retain the first seen HELP (description) and UNIT (unit) metadata, log a warning, and keep all data points when two metrics resolve to the same Prometheus metric name with conflicting descriptions or units.

Fixes #3072

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • pytest exporter/opentelemetry-exporter-prometheus/tests (added unit tests for multi-scope/label-set grouping, HELP conflicts, UNIT conflicts, TYPE conflicts across counter/gauge and gauge/histogram, and multiple queued MetricsData items in a single scrape)
  • ruff check / ruff format --check / pylint

Does This PR Require a Core Repo Change?

  • No.

dashpole added a commit to dashpole/opentelemetry-python that referenced this pull request Nov 12, 2026
@dashpole
dashpole force-pushed the prometheus-metric-metadata-collisions branch from d8526bf to f8b52f2 Compare November 12, 2026 05:12
@dashpole
dashpole requested a balanced review from Copilot November 12, 2026 05:12

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 12, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-12-01 16:19 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with the author? Comment /dashboard route:author to route it back.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@dashpole
dashpole marked this pull request as ready for review November 12, 2026 14:44
@dashpole
dashpole requested a review from a team as a code owner November 12, 2026 14:44
@herin049

herin049 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Maybe I'm missing something obvious here, but why do we need _PendingMetricFamily, can we not keep the current approach of building the Prometheus metric families as they are encountered?

I'm assuming we can just do the following:

  • Create appropriate metric family on first encounter (already handled)
  • Determine if the metric type matches the existing family type (if not drop)
  • Determine if the metric unit/description matches the existing family (if not log a warning)

This approach should naturally still handle the two requirements:

Drop conflicting metrics and log a warning when two metrics resolve to the same Prometheus metric name with conflicting TYPEs (e.g. counter foo vs gauge foo_total, or gauge vs histogram).

Retain the first seen HELP (description) and UNIT (unit) metadata, log a warning, and keep all data points when two metrics resolve to the same Prometheus metric name with conflicting descriptions or units.

dashpole added a commit to dashpole/opentelemetry-python that referenced this pull request Nov 17, 2026
@dashpole
dashpole force-pushed the prometheus-metric-metadata-collisions branch from f8b52f2 to a2f6b59 Compare November 17, 2026 16:16
@dashpole

Copy link
Copy Markdown
Contributor Author

Maybe I'm missing something obvious here, but why do we need _PendingMetricFamily, can we not keep the current approach of building the Prometheus metric families as they are encountered?

CounterMetricFamily, GaugeMetricFamily, and HistogramMetricFamily freeze labels in __init__, and add_metric zips positional label values against that initial key list. When two scopes emit the same metric with different attribute keys (for example {k1="v1"} in scope1 and {k2="v2"} in scope2), I need the union of label keys across all matching metrics in the scrape before constructing the family so add_metric aligns keys properly and backfills "" for missing labels.

@dashpole
dashpole requested a review from herin049 November 17, 2026 16:17
@dashpole

Copy link
Copy Markdown
Contributor Author

/dashboard route:reviewers

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

@dashpole, this pull request was routed to reviewers. The handoff remains active across pushes until newer actionable human feedback arrives. Top-level feedback through this request will not return; unresolved review threads remain open.

@herin049

Copy link
Copy Markdown
Contributor

Maybe I'm missing something obvious here, but why do we need _PendingMetricFamily, can we not keep the current approach of building the Prometheus metric families as they are encountered?

CounterMetricFamily, GaugeMetricFamily, and HistogramMetricFamily freeze labels in __init__, and add_metric zips positional label values against that initial key list. When two scopes emit the same metric with different attribute keys (for example {k1="v1"} in scope1 and {k2="v2"} in scope2), I need the union of label keys across all matching metrics in the scrape before constructing the family so add_metric aligns keys properly and backfills "" for missing labels.

Ok, I see now, sorry I missed this.

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Dec 1, 2026
dashpole added a commit to dashpole/opentelemetry-python that referenced this pull request Dec 1, 2026
@dashpole
dashpole force-pushed the prometheus-metric-metadata-collisions branch from 0eac65d to 13d05c9 Compare December 1, 2026 17:00
dashpole added a commit to dashpole/opentelemetry-python that referenced this pull request Dec 2, 2026
@dashpole
dashpole force-pushed the prometheus-metric-metadata-collisions branch from 13d05c9 to 3f11c03 Compare December 2, 2026 14:01
@dashpole
dashpole force-pushed the prometheus-metric-metadata-collisions branch from 3f11c03 to 6ef50b4 Compare December 3, 2026 13:49

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status
Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

Prometheus exporter handles instrumentation scope and prevents collisions

4 participants