Skip to content

[EXPORTER] Prometheus exporter: export instrumentation scope schema URL and attributes as labels - #4735

Open
dashpole wants to merge 1 commit into
open-telemetry:mainfrom
dashpole:prom-scope-labels-1841
Open

dashpole wants to merge 1 commit into
open-telemetry:mainfrom
dashpole:prom-scope-labels-1841

Conversation

@dashpole

@dashpole dashpole commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1841

Changes

Update PrometheusExporterUtils::SetMetricBasic to conform to the Instrumentation Scope section of the OpenTelemetry Prometheus and OpenMetrics Compatibility Specification:

  • Export otel_scope_schema_url when InstrumentationScope::GetSchemaURL() is non-empty and without_otel_scope is false.
  • Export InstrumentationScope attributes as labels with the otel_scope_ prefix, dropping scope attributes that conflict with otel_scope_name, otel_scope_version, or otel_scope_schema_url after sanitization, and concatenating values with ; in lexicographical order of original keys when sanitized keys collide.

(Pre-existing bug fixes for array attribute serialization, cross-source otel_scope_* point attribute collisions, and empty point attribute guards 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

Unresolved label collisions can produce invalid Prometheus samples, and array-valued scope attributes lose their values.

2 open issues
What changed in this PR

This PR extends Prometheus instrumentation-scope labels with schema URLs and scope attributes, advancing the exporter compatibility work in #1841.

Changes:

  • Adds schema URL and prefixed scope-attribute labels, with reserved-name filtering and scope-attribute collision handling.
  • Preserves scope labels when point attributes and the resource are absent.
  • Adds regression tests and updates API documentation and the changelog.
File Description
exporters/​prometheus/​test/​exporter_utils_test.cc Tests scope labels, opt-out behavior, and scope-attribute collisions.
exporters/​prometheus/​src/​exporter_utils.cc Implements expanded scope labels and adjusts the early return.
exporters/​prometheus/​include/​opentelemetry/​exporters/​prometheus/​exporter_utils.h Documents the expanded scope-label option.
CHANGELOG.md Records the exporter enhancement.

Review effort: Balanced

Comment thread exporters/prometheus/src/exporter_utils.cc
Comment thread exporters/prometheus/src/exporter_utils.cc
@dashpole
dashpole force-pushed the prom-scope-labels-1841 branch from 789024b to a27834e Compare October 25, 2026 15:31
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.73%. Comparing base (e854d29) to head (98be712).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4735      +/-   ##
==========================================
+ Coverage   86.69%   86.73%   +0.05%     
==========================================
  Files         527      527              
  Lines       20902    20932      +30     
==========================================
+ Hits        18119    18154      +35     
+ Misses       2783     2778       -5     
Files with missing lines Coverage Δ
exporters/prometheus/src/exporter_utils.cc 91.02% <100.00%> (+1.81%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dashpole
dashpole force-pushed the prom-scope-labels-1841 branch from a27834e to 86ab04f Compare October 25, 2026 16:12
@dashpole
dashpole requested a balanced review from Copilot October 25, 2026 19:58

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.

…RL and attributes as labels

Update PrometheusExporterUtils::SetMetricBasic to conform to the OpenTelemetry Prometheus and OpenMetrics compatibility specification:
- Export otel_scope_schema_url when InstrumentationScope::GetSchemaURL() is non-empty and without_otel_scope is false.
- Export InstrumentationScope attributes as labels with the otel_scope_ prefix, dropping scope attributes that conflict with otel_scope_name, otel_scope_version, or otel_scope_schema_url after sanitization, and concatenating values with ';' in lexicographical order of original keys when sanitized keys collide.

Part of open-telemetry#1841
@dashpole
dashpole force-pushed the prom-scope-labels-1841 branch from f597923 to 98be712 Compare October 26, 2026 18:17
@dashpole
dashpole marked this pull request as ready for review October 26, 2026 18:37
@dashpole
dashpole requested a review from a team as a code owner October 26, 2026 18:37

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