Skip to content

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

Open
dashpole wants to merge 1 commit into
open-telemetry:mainfrom
dashpole:prometheus-metric-metadata-collisions
Open

dashpole wants to merge 1 commit 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
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 the author · refreshed 2026-11-15 08:34 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1
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 reviewers? Comment /dashboard route:reviewers to route it to them.
  • 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.

def _populate_counter_family(
registry: dict[str, PrometheusMetric],
per_metric_family_id: str,
def _resolve_prometheus_name(

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 know that OTel defaults to Prometheus text format, but what about OpenMetrics? E.g. if I have counter foo and gauge foo, then OpenMetrics will have the following type lines:

# TYPE foo counter
# TYPE foo gauge

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 handles instrumentation scope and prevents collisions

3 participants