Skip to content

Add support for excluding attributes in metrics View#5332

Open
saurabh-saraswat wants to merge 8 commits into
open-telemetry:mainfrom
saurabh-saraswat:exclude_attribute
Open

Add support for excluding attributes in metrics View#5332
saurabh-saraswat wants to merge 8 commits into
open-telemetry:mainfrom
saurabh-saraswat:exclude_attribute

Conversation

@saurabh-saraswat

@saurabh-saraswat saurabh-saraswat commented Jun 19, 2026

Copy link
Copy Markdown

Description

Added support for parameter exclude_attribute_keys in View. During consume_measurement removed the attributes which were in exclude_attribute_keys

Fixes #5331

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [ ✔ ] Use exclude parameter while creating view like 👍
  view = View(
            instrument_name="api_counter",
            exclude_attribute_keys={"email", "phone"},
        )

Does This PR Require a Contrib Repo Change?

No

Checklist:

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

@saurabh-saraswat saurabh-saraswat requested a review from a team as a code owner June 19, 2026 09:53
@xrmx xrmx changed the title Exclude attribute Add support for excluding attributes in metrics view Jun 22, 2026
@xrmx xrmx changed the title Add support for excluding attributes in metrics view Add support for excluding attributes in metrics View Jun 22, 2026
Comment thread .changelog/5332.fixed Outdated
@xrmx xrmx moved this to Ready for review in Python PR digest Jun 30, 2026

@xrmx xrmx 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.

Looks like you haven't run the tests locally

@github-project-automation github-project-automation Bot moved this from Ready for review to Reviewed PRs that need fixes in Python PR digest Jul 1, 2026
saurabh-saraswat and others added 2 commits July 1, 2026 16:40
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
@saurabh-saraswat

saurabh-saraswat commented Jul 2, 2026

Copy link
Copy Markdown
Author

@xrmx . I have updated the pull request for the comments provided. Local tests was passing.

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 View-level support for excluding specific attribute keys from metric stream identity, aligning the Python SDK View API with the Metrics SDK spec’s exclude-list behavior (issue #5331).

Changes:

  • Introduces exclude_attribute_keys on View and applies it during measurement consumption to remove matching keys before stream identification.
  • Updates declarative meter provider configuration to map attribute_keys.excluded into View(exclude_attribute_keys=...).
  • Adds/updates unit tests and changelog entry for the new behavior.

Reviewed changes

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

Show a summary per file
File Description
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py Adds exclude_attribute_keys to the View API and stores it for later use.
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/_view_instrument_match.py Applies the exclude-list while building the attribute set used for aggregation keying.
opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_meter_provider.py Wires declarative config’s excluded attribute keys into the SDK View.
opentelemetry-sdk/tests/metrics/test_view_instrument_match.py Adds tests validating exclude-list behavior and include-then-exclude precedence.
opentelemetry-sdk/tests/_configuration/test_meter_provider.py Updates config test to assert excluded attribute keys are applied to View.
.changelog/5332.added Documents the added View(exclude_attribute_keys=...) support.

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

self._exemplar_reservoir_factory = (
exemplar_reservoir_factory or _default_reservoir_factory
)
self._exclude_attribute_keys = exclude_attribute_keys

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is true for other member variables used during creation of View as well.

Comment on lines +101 to +107
if self._view._exclude_attribute_keys is not None:
if attributes is not None:
attributes = {
key: value
for key, value in attributes.items()
if key not in self._view._exclude_attribute_keys
}

@saurabh-saraswat saurabh-saraswat left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated for github review comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Support for exclude list is missing in attributes

4 participants