Add support for excluding attributes in metrics View#5332
Add support for excluding attributes in metrics View#5332saurabh-saraswat wants to merge 8 commits into
Conversation
xrmx
left a comment
There was a problem hiding this comment.
Looks like you haven't run the tests locally
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
|
@xrmx . I have updated the pull request for the comments provided. Local tests was passing. |
There was a problem hiding this comment.
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_keysonViewand applies it during measurement consumption to remove matching keys before stream identification. - Updates declarative meter provider configuration to map
attribute_keys.excludedintoView(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 |
There was a problem hiding this comment.
This is true for other member variables used during creation of View as well.
| 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
left a comment
There was a problem hiding this comment.
Updated for github review comments
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.
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
Does This PR Require a Contrib Repo Change?
No
Checklist: