Skip to content

opentelemetry-sdk: add support for exclude list for metric attribute keys on Views#5447

Closed
herin049 wants to merge 2 commits into
open-telemetry:mainfrom
herin049:feat/view-excluded-attribute-keys
Closed

opentelemetry-sdk: add support for exclude list for metric attribute keys on Views#5447
herin049 wants to merge 2 commits into
open-telemetry:mainfrom
herin049:feat/view-excluded-attribute-keys

Conversation

@herin049

Copy link
Copy Markdown
Contributor

Description

Adds support for configuring an exclude list for metric attribute keys for Views.

Fixes #5446

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-sdk

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 July 20, 2026 02:40
@herin049
herin049 requested a review from Copilot July 20, 2026 02:42
@herin049 herin049 added Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary metrics labels Jul 20, 2026

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 OpenTelemetry Metrics SDK support for configuring an exclude list of metric attribute keys on Views, aligning behavior with the Views specification guidance and propagating that capability through declarative configuration.

Changes:

  • Extends View to accept excluded_attribute_keys and validates it does not overlap with attribute_keys.
  • Applies include/exclude attribute-key filtering in _ViewInstrumentMatch.consume_measurement.
  • Updates configuration parsing and expands unit tests to cover excluded keys behavior.

Reviewed changes

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

Show a summary per file
File Description
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py Adds excluded_attribute_keys to View, normalizes inputs, and validates include/exclude overlap.
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/_view_instrument_match.py Implements attribute filtering logic that supports both include and exclude sets.
opentelemetry-sdk/tests/metrics/test_view.py Adds tests for include/exclude overlap, disjoint keys, and normalization behavior.
opentelemetry-sdk/tests/metrics/test_view_instrument_match.py Adds tests asserting excluded keys are dropped during measurement consumption.
opentelemetry-configuration/src/opentelemetry/configuration/_meter_provider.py Maps declarative config attribute_keys.excluded into SDK View(excluded_attribute_keys=...).
opentelemetry-configuration/tests/test_meter_provider.py Updates tests to assert excluded keys are passed through (instead of warning/ignoring).
.changelog/5447.added Adds changelog entry for the new View exclude-list feature.

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

Comment on lines +149 to +153
excluded_attribute_keys = (
frozenset(excluded_attribute_keys)
if excluded_attribute_keys is not None
else None
)
Comment on lines 260 to 264
name=stream.name,
description=stream.description,
attribute_keys=attribute_keys,
excluded_attribute_keys=excluded_attribute_keys,
aggregation=aggregation,
@xrmx

xrmx commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Isn't this a dup of #5332?

@herin049

Copy link
Copy Markdown
Contributor Author

Isn't this a dup of #5332?

Thanks, missed this.

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 metrics

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

metrics: support exclude list for metric attribute keys for Views

3 participants