open-telemetry / open-telemetry/opentelemetry-python

Creating named `View` with only `instrument_type` does not raise error

Open
#2,815 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

Describe your problem

This might not be a bug, but not consistent with the specification. 🙂

Creating a named View with only instrument_type does not raise an Error, even though it implicitly selects multiple instruments on the same meter.

From the 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.

Here, only providing the instrument_type without providing an instrument_name has the same effect as providing a wildcard instrument_name, therefore it may be selecting multiple instruments.

Describe your environment

Python version: any
Metrics SDK version: v0.32b0

Steps to reproduce

Run:

from opentelemetry.sdk.metrics import MeterProvider, Counter
from opentelemetry.sdk.metrics.view import View

MeterProvider(views=[View(name="name", instrument_type=Counter)])

What is the expected behavior?

An Error similar to when only a wildcard is provided.

What is the actual behavior?

No Error is raised.

Additional context

When running

MeterProvider(views=[View(name="name", instrument_name="*", instrument_type=Counter)])

an error is thrown, even though it is semantically the same as the example provided in the "Steps to reproduce"-section above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the View and MeterProvider entry points shown in the reproduction, comparing validation for an omitted instrument_name with the wildcard case. Run both provided examples and add coverage showing that a named View with only instrument_type raises the expected error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.