Skip to content

fix(prometheus-exporter): align label sets across instruments sharing a metric family - #5918

Open
anjalimishra-0007 wants to merge 2 commits into
open-telemetry:mainfrom
anjalimishra-0007:fix/prometheus-multi-instrument-family-labels
Open

anjalimishra-0007 wants to merge 2 commits into
open-telemetry:mainfrom
anjalimishra-0007:fix/prometheus-multi-instrument-family-labels

Conversation

@anjalimishra-0007

Copy link
Copy Markdown

Description

Fixes #5685

When two instruments (for example across different instrumentation scopes) share the same Prometheus metric family ID (metric_name, description, unit, and family type), _CustomCollector previously created the *MetricFamily using only the first metric's sorted label keys and then appended subsequent metrics' points positionally. If another instrument carried additional or different attribute keys, values were shifted into the wrong label names or silently truncated.

This change introduces _PendingMetricFamily inside exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/__init__.py so _CustomCollector.collect gathers data points across all metrics and queued MetricsData batches sharing a family ID first, computes the unified sorted label-key union, and backfills missing labels with "" before instantiating and populating each Prometheus family once.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I am a human and not a bot
  • I have run tox -e precommit
  • I have run tox -e typecheck
  • I have run the relevant tests and linting tox environments

Testing & checks run locally in an isolated Python 3.13 virtualenv (exporter/opentelemetry-exporter-prometheus):

  • pytest exporter/opentelemetry-exporter-prometheus/tests -v: 44 passed (including new tests for histograms, counters, gauges, and queued MetricsData batches sharing metric families across scopes/label sets)
  • ruff check exporter/opentelemetry-exporter-prometheus: all checks passed
  • ruff format --check exporter/opentelemetry-exporter-prometheus: all 7 files formatted
  • pylint --rcfile ../.pylintrc opentelemetry-exporter-prometheus: 10.00/10

… a metric family

Assisted-by: Google Antigravity
Signed-off-by: Anjali Mishra <246823347+anjalimishra-0007@users.noreply.github.com>
@anjalimishra-0007
anjalimishra-0007 requested a review from a team as a code owner November 11, 2026 09:41
@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@opentelemetry-pr-dashboard

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

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-11-11 10:52 UTC

Review the latest changes.

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.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Assisted-by: Google Antigravity
Signed-off-by: Anjali Mishra <246823347+anjalimishra-0007@users.noreply.github.com>

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

Development

Successfully merging this pull request may close these issues.

Prometheus exporter puts label values under the wrong label names when two instruments share a name

1 participant