Skip to content

feat: add support for configuring metric scope labels#5123

Merged
aabmass merged 18 commits into
open-telemetry:mainfrom
herin049:feat/prometheus-scope-info
Jun 17, 2026
Merged

feat: add support for configuring metric scope labels#5123
aabmass merged 18 commits into
open-telemetry:mainfrom
herin049:feat/prometheus-scope-info

Conversation

@herin049

@herin049 herin049 commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds support for configuring scope labels on the Prometheus exporter in accordance with the Prometheus spec The default behavior is to include scope labels in exported metrics.

Furthermore this PR includes changes to refactor the conversion of OTel metrics to Prometheus metrics.

Fixes #5112

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

uv run tox -e py314-test-opentelemetry-exporter-prometheus

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@herin049 herin049 requested a review from a team as a code owner April 18, 2026 04:33
@herin049 herin049 added the Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary label Apr 18, 2026
@herin049 herin049 moved this to Ready for review in Python PR digest Apr 18, 2026

@MikeGoldsmith MikeGoldsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like it's on the right path. A few things to note:

  1. _SCOPE_ATTR_CONFLICT_NAMES is defined but never used — we should either use it to explicitly filter conflicting scope attributes or remove it.

  2. PR description looks copy-pasted from #5122 — says "Resource metrics as Metric attributes" but this is about scope info.

  3. Merge conflict concern — this, #5122, #5118, and #5117 all modify PrometheusMetricReader and _translate_to_prometheus. This is going to conflict with them, we need to coordinate what should be done in order or we'll be bumping into each other with rebases.

  4. nit: the nesting depth in _translate_to_prometheus is getting deep — might be worth extracting the per-metric logic into a helper in a follow-up.

@MikeGoldsmith MikeGoldsmith moved this from Ready for review to Approved PRs that need fixes in Python PR digest Apr 21, 2026
@herin049

Copy link
Copy Markdown
Contributor Author

This looks like it's on the right path. A few things to note:

  1. _SCOPE_ATTR_CONFLICT_NAMES is defined but never used — we should either use it to explicitly filter conflicting scope attributes or remove it.
  2. PR description looks copy-pasted from opentelemetry-exporter-prometheus: add support to configure Resource attributes as metric labels #5122 — says "Resource metrics as Metric attributes" but this is about scope info.
  3. Merge conflict concern — this, opentelemetry-exporter-prometheus: add support to configure Resource attributes as metric labels #5122, feat: add metric name translation strategy support for the Prometheus exporter #5118, and feat(exporter/prometheus): add default_aggregation parameter to PrometheusMetricReader #5117 all modify PrometheusMetricReader and _translate_to_prometheus. This is going to conflict with them, we need to coordinate what should be done in order or we'll be bumping into each other with rebases.
  4. nit: the nesting depth in _translate_to_prometheus is getting deep — might be worth extracting the per-metric logic into a helper in a follow-up.

Sorry, got a little sloppy with this PR. I originally used _SCOPE_ATTR_CONFLICT_NAMES, but refactored the code so that it isn't needed anymore. The update order shouldn't matter much, I can address the merge conflicts as they come in. Updated the PR description, will clean up the PR.

@herin049

Copy link
Copy Markdown
Contributor Author

@MikeGoldsmith I ended up doing a pretty major refactor of the exporter logic based on your suggestion, so we will likely want to merge this PR first.

@herin049 herin049 moved this from Approved PRs that need fixes to Ready for review in Python PR digest Apr 22, 2026

@MikeGoldsmith MikeGoldsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks @herin049. Need to update PR title and description.

@github-project-automation github-project-automation Bot moved this from Ready for review to Approved PRs in Python PR digest Apr 24, 2026
@herin049 herin049 changed the title feat: add support for configuring scope info metric attributes for the Prometheus exporter feat: add support for configuring scope info metric attributes for the Prometheus exporter and refactor conversion to Prometheus metrics Apr 24, 2026
@herin049 herin049 force-pushed the feat/prometheus-scope-info branch from ef6fede to 4a590f0 Compare April 25, 2026 03:39
@herin049 herin049 force-pushed the feat/prometheus-scope-info branch from 4a590f0 to be41170 Compare April 29, 2026 21:22
@ArthurSens

ArthurSens commented May 6, 2026

Copy link
Copy Markdown
Member

Hey, just a heads-up from the Prometheus SIG: please hold off on the merge here. There's on going discussion happening on the PR that stabilizes this part of the spec open-telemetry/opentelemetry-specification#5056

@MikeGoldsmith

Copy link
Copy Markdown
Member

Moving to draft until the SIG confirms this is the correct path.

@MikeGoldsmith MikeGoldsmith marked this pull request as draft May 7, 2026 14:16
reyang pushed a commit to johannaojeling/opentelemetry-specification that referenced this pull request May 13, 2026
…en-telemetry#5056)

Fixes open-telemetry#4989

## Changes

Stabilizes the configuration option `without_scope_info`, documented in
the Prometheus exporter spec. It is implemented by a few SDKs already
open-telemetry#4989 (comment),
an open PR for
Python(open-telemetry/opentelemetry-python#5123),
and an issue for
DotNet(open-telemetry/opentelemetry-dotnet#7157).
Both prometheus exporters in the collector have the option as
well[[1](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/prometheusexporter#:~:text=without_scope_info%3A%20(default%20%3D%20false)%3A%20If%20true%2C%20metrics%20will%20be%20exported%20without%20scope%20name%2C%20version%2C%20schemaURL%2C%20and%20attributes%20encoded%20as%20labels.)][[2](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/prometheusremotewriteexporter#:~:text=disable_scope_info%20(default%20%3D%20false)%3A%20If%20true%2C%20the%20scope%20info%20labels%20(otel_scope_name%2C%20otel_scope_version%20and%20otel_scope_...%20attributes)%20will%20not%20be%20exported.)]
(Although remote write exporter uses `disable_scope_info` instead of
`without_scope_info`.

For non-trivial changes, follow the [change proposal
process](https://github.com/open-telemetry/opentelemetry-specification/blob/main/CONTRIBUTING.md#proposing-a-change).

* [X] Related issues open-telemetry#4989 
* [ ] Related [OTEP(s)](https://github.com/open-telemetry/oteps) #
* [ ] Links to the prototypes (when adding or changing features)
* [X]
[`CHANGELOG.md`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/CHANGELOG.md)
file updated for non-trivial changes
* For trivial changes, include `[chore]` in the PR title to skip the
changelog check
* [ ] [Spec compliance
matrix](https://github.com/open-telemetry/opentelemetry-specification/blob/main/spec-compliance-matrix/template.yaml)
updated if necessary
* [ ] [Declarative config data
model](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/data-model.md#overview)
is updated if SDK config surface is changed

---------

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@herin049 herin049 marked this pull request as ready for review May 13, 2026 16:07
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Jun 3, 2026
@herin049 herin049 removed the Stale label Jun 4, 2026
Comment thread exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py Outdated
@aabmass aabmass moved this from Approved PRs to Approved PRs that need fixes in Python PR digest Jun 5, 2026
@herin049 herin049 requested a review from aabmass June 10, 2026 03:25
@herin049 herin049 moved this from Approved PRs that need fixes to Approved PRs in Python PR digest Jun 13, 2026
Comment thread .changelog/5123.added Outdated
@aabmass aabmass enabled auto-merge June 16, 2026 20:05
@herin049 herin049 changed the title feat: add support for configuring scope info metric attributes for the Prometheus exporter and refactor conversion to Prometheus metrics feat: add support for configuring metric scope labels Jun 17, 2026
@herin049 herin049 requested a review from Copilot June 17, 2026 01:30

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.

Pull request overview

Adds Prometheus exporter support for including (and optionally disabling) instrumentation scope labels on exported metrics, aligning the exporter with the spec’s Scope Info guidance, and refactors the OTel→Prometheus translation pipeline to be more modular.

Changes:

  • Add scope label emission (otel_scope_name, otel_scope_version, otel_scope_schema_url, and otel_scope_* scope attributes) with a toggle (scope_info_enabled).
  • Refactor metric translation into helper functions for family creation/population and data-point collection.
  • Add/adjust unit tests and update Prometheus exporter documentation and changelog entry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py Adds tests for default/disabled scope labels and updates existing tests to account for new default behavior.
exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/init.py Implements scope label handling and refactors translation logic into smaller helpers.
docs/exporter/prometheus/prometheus.rst Documents scope label behavior and configuration.
.changelog/5123.added Notes the new Prometheus exporter feature.
Comments suppressed due to low confidence (1)

exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/init.py:288

  • This PR adds scope_info_enabled on PrometheusMetricReader, but the SDK's config-based Prometheus factory still logs that without_scope_info is unsupported and ignores it (opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_meter_provider.py, around _create_prometheus_metric_reader). That means "configuring scope labels" won't work for users relying on SDK configuration / opentelemetry-instrument unless that path is updated (or an alias parameter is supported).
    def __init__(
        self,
        disable_target_info: bool = False,
        prefix: str = "",
        scope_info_enabled: bool = True,
        *,
        registry: CollectorRegistry = REGISTRY,
    ) -> None:
        super().__init__(
            preferred_temporality={
                Counter: AggregationTemporality.CUMULATIVE,
                UpDownCounter: AggregationTemporality.CUMULATIVE,
                HistogramInstrument: AggregationTemporality.CUMULATIVE,
                ObservableCounter: AggregationTemporality.CUMULATIVE,
                ObservableUpDownCounter: AggregationTemporality.CUMULATIVE,
                ObservableGauge: AggregationTemporality.CUMULATIVE,
            },
            otel_component_type=OtelComponentTypeValues.PROMETHEUS_HTTP_TEXT_METRIC_EXPORTER,
        )
        self._collector = _CustomCollector(
            disable_target_info=disable_target_info,
            prefix=prefix,
            scope_info_enabled=scope_info_enabled,
        )
        self._registry = registry
        self._registry.register(self._collector)
        self._collector._callback = self.collect
        self._prefix = prefix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/exporter/prometheus/prometheus.rst Outdated
@aabmass aabmass added this pull request to the merge queue Jun 17, 2026
Merged via the queue into open-telemetry:main with commit 97dfa13 Jun 17, 2026
520 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary exporters

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Stabilize Prometheus Exporter: Scope Info

6 participants