Skip to content

fix(sdk): raise error when named view specifies no instrument name (#2815) - #5631

Open
dlowzzxx wants to merge 1 commit into
open-telemetry:mainfrom
dlowzzxx:fix/view-name-instrument-selection-2815
Open

fix(sdk): raise error when named view specifies no instrument name (#2815)#5631
dlowzzxx wants to merge 1 commit into
open-telemetry:mainfrom
dlowzzxx:fix/view-name-instrument-selection-2815

Conversation

@dlowzzxx

@dlowzzxx dlowzzxx commented Sep 5, 2026

Copy link
Copy Markdown

Description

According to the OpenTelemetry Metrics SDK Specification:

In order to avoid conflicts, views which specify a name SHOULD have an instrument selector that selects at most one instrument. For the registration mechanism described above, where selection is provided via configuration, the SDK SHOULD NOT allow Views with a specified name to be declared with instrument selectors that may select more than one instrument (e.g. wild card instrument name) in the same Meter.

Previously, View validation checked for wildcard characters in instrument_name only when instrument_name is not None. However, omitting instrument_name while specifying name (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 an Exception when name is specified but instrument_name is omitted (None), ensuring consistency with the specification and wildcard validation.

Fixes #2815

Type of change

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

How Has This Been Tested?

  • Added unit tests in opentelemetry-sdk/tests/metrics/test_view.py:
    • test_view_name_wildcard: asserts wildcard characters (*, ?) in named views continue to raise Exception.
    • test_view_name_without_instrument_name: asserts defining a named View without instrument_name (e.g., with instrument_type, meter_name, instrument_unit, meter_version, meter_schema_url) raises Exception.
    • test_view_name_with_concrete_instrument_name: asserts that named views with concrete instrument_name work as expected.
  • Verified test suite:
    • 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 check and ruff format --check passed cleanly.

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

@dlowzzxx
dlowzzxx requested a review from a team as a code owner September 5, 2026 19:38
@dlowzzxx
dlowzzxx force-pushed the fix/view-name-instrument-selection-2815 branch from f24a795 to e1b9725 Compare September 5, 2026 19:42
@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-09-05 21:19 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Creating named View with only instrument_type does not raise error

1 participant