Conversation
dlowzzxx
force-pushed
the
fix/view-name-instrument-selection-2815
branch
from
September 5, 2026 19:42
f24a795 to
e1b9725
Compare
Pull request dashboard statusWaiting on maintainers · refreshed 2026-09-29 22:27 UTC Resolve merge conflicts, then merge when ready. Status above doesn't look right?
|
herin049
approved these changes
Sep 11, 2026
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Bracket wildcard patterns can still allow a named view to match multiple instruments.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Updates Metrics SDK View validation to prevent named views from broadly selecting instruments.
Changes:
- Requires named views to specify
instrument_name. - Adds validation tests and documentation.
- Adds a changelog entry.
| File | Description |
|---|---|
opentelemetry-sdk/tests/metrics/test_view.py |
Tests named-view validation. |
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py |
Enforces instrument-name requirements. |
.changelog/5631.fixed |
Documents the fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| raise Exception( | ||
| f"View {name} specifies a name but no instrument_name, which may select multiple instruments" | ||
| ) | ||
| if "*" in instrument_name or "?" in instrument_name: |
Assisted-by: OpenAI Codex
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
According to the OpenTelemetry Metrics SDK Specification:
Previously,
Viewvalidation checked for wildcard characters ininstrument_nameonly wheninstrument_name is not None. However, omittinginstrument_namewhile specifyingname(e.g.View(name="custom_name", instrument_type=Counter)) implicitly selects all instruments matching that type or meter criteria, which may select multiple instruments in the same Meter.This PR adds a check in
View.__init__that raises anExceptionwhennameis specified butinstrument_nameis omitted (None), ensuring consistency with the specification and wildcard validation.Fixes #2815
Type of change
How Has This Been Tested?
opentelemetry-sdk/tests/metrics/test_view.py:test_view_name_wildcard: asserts wildcard characters (*,?) in named views continue to raiseException.test_view_name_without_instrument_name: asserts defining a named View withoutinstrument_name(e.g., withinstrument_type,meter_name,instrument_unit,meter_version,meter_schema_url) raisesException.test_view_name_with_concrete_instrument_name: asserts that named views with concreteinstrument_namework as expected.pytest opentelemetry-sdk/tests/metrics/test_view.py opentelemetry-sdk/tests/metrics/test_view_instrument_match.py opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py(47/47 passing).ruff checkandruff format --checkpassed cleanly.Does This PR Require a Contrib Repo Change?
Checklist: