Skip to content

[EXPORTER] Prometheus exporter: merge metric families across scopes and drop conflicting metric types - #4736

Open
dashpole wants to merge 1 commit into
open-telemetry:mainfrom
dashpole:prom-metric-collisions-1841
Open

dashpole wants to merge 1 commit into
open-telemetry:mainfrom
dashpole:prom-metric-collisions-1841

Conversation

@dashpole

@dashpole dashpole commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1841

Changes

Update PrometheusExporterUtils::TranslateToPrometheus to conform to the Metric Metadata section of the OpenTelemetry Prometheus and OpenMetrics Compatibility Specification:

  • Merge metrics across scopes (or unit/suffix-stripped instruments) that translate to the same Prometheus metric name and MetricType into a single MetricFamily so duplicate # HELP and # TYPE headers are not emitted. When descriptions differ, retain the first HELP description and log a warning.
  • Drop metrics that translate to an existing Prometheus metric name with a conflicting MetricType and log a warning.

(Pre-existing bug fixes have been split into #4738.)

For full trivial changes below, please confirm you have:

  • Formatted the code using clang-format
  • Updated CHANGELOG.md if applicable

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Collision handling uses the generated Info family’s internal name and type rather than its Prometheus text representation, causing incorrect drops and missed collisions.

1 open issue
What changed in this PR

This PR advances #1841 by handling metric-family collisions in the Prometheus exporter, reducing duplicate metadata across instrumentation scopes.

Changes:

  • Merge families with matching translated names and types, keeping the first description and warning on differences.
  • Drop conflicting metric types and skip empty point collections.
  • Add collision regression coverage and a changelog entry.
File Description
exporters/​prometheus/​test/​exporter_utils_test.cc Tests cross-scope merging, description retention, and type-conflict dropping.
exporters/​prometheus/​src/​exporter_utils.cc Adds family indexing, collision handling, and an empty-point guard.
CHANGELOG.md Documents the exporter behavior change under Unreleased.

Review effort: Balanced

Comment thread exporters/prometheus/src/exporter_utils.cc Outdated
@dashpole
dashpole force-pushed the prom-metric-collisions-1841 branch 2 times, most recently from 2daf2ce to 4cbcfa3 Compare October 25, 2026 16:12
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.70%. Comparing base (e854d29) to head (d763e4d).

Files with missing lines Patch % Lines
exporters/prometheus/src/exporter_utils.cc 96.43% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4736      +/-   ##
==========================================
+ Coverage   86.69%   86.70%   +0.02%     
==========================================
  Files         527      527              
  Lines       20902    20916      +14     
==========================================
+ Hits        18119    18134      +15     
+ Misses       2783     2782       -1     
Files with missing lines Coverage Δ
exporters/prometheus/src/exporter_utils.cc 89.97% <96.43%> (+0.77%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dashpole
dashpole requested a balanced review from Copilot October 25, 2026 19:59

Copilot AI left a comment

Copy link
Copy Markdown

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.

@dashpole
dashpole marked this pull request as ready for review October 26, 2026 13:48
@dashpole
dashpole requested a review from a team as a code owner October 26, 2026 13:48
…nd drop conflicting metric types

Update PrometheusExporterUtils::TranslateToPrometheus to conform to the Metric Metadata section of the OpenTelemetry Prometheus and OpenMetrics compatibility specification:
- Merge metrics across scopes (or unit/suffix-stripped instruments) that map to the same Prometheus metric name and MetricType into a single MetricFamily, retaining the first HELP description and logging a warning on description mismatch.
- Drop metrics that map to an existing Prometheus metric name with a conflicting MetricType and log a warning.

Part of open-telemetry#1841

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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants