You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] View initialization fails to detect character pattern wildcards ('[', ']') in instrument_name when name is set #5664
"If name is provided, the View MUST match at most one instrument. If instrument_name contains wildcard characters (*, ?, [seq], [!seq]), name MUST NOT be provided."
In opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py, View.__init__ checks for wildcard characters when a custom name is provided:
if name is not None and instrument_name is not None and ("*" in instrument_name or "?" in instrument_name):
raise Exception(f"View {name} declared with wildcard characters in instrument_name")
However, instrument matching is performed using fnmatch.fnmatchcase() (line 153), which supports character sequence wildcards such as [seq] and [!seq] (e.g. http_[0-9]).
Because View.__init__ only checks for * and ?, passing a wildcard pattern containing [ or ] (e.g. instrument_name="http_[0-9]") alongside a custom name (e.g. name="custom_name") fails to raise an Exception. This allows a single renamed View stream to match multiple instruments, violating the specification constraint.
Steps to Reproduce
from opentelemetry.sdk.metrics.view import View
Should raise Exception because 'http_[0-9]' contains fnmatch wildcard '[', but currently succeeds:
v = View(name="custom_name", instrument_name="http_[0-9]")
Expected Result
View(name="custom_name", instrument_name="http_[0-9]") should raise an Exception during initialization, matching the behavior when '*' or '?' is used.
Actual Result
View initializes without error and matches multiple instruments (e.g., http_1, http_2), renaming all of them to custom_name.
Additional context
Suggested fix in opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py:
if name is not None and instrument_name is not None and any(c in instrument_name for c in "*?["):
raise Exception(f"View {name} declared with wildcard characters in instrument_name")
If it's still free, i can take it.
I checked it against main: View(name="custom_name", instrument_name="http_[0-9]") initialises without error, and fnmatchcase then matches both http_1 and http_2, so a named view can match more than one instrument, which is what the spec forbids. The guard at view.py:122 only looks for * and ?. I would extend it to reject [ as well, since fnmatch treats *, ? and [ as the metacharacters, and add a regression test next to test_view_name.
Does that direction work, and are you still planning to open the PR yourself?
Hey @somuai@axiom-of-choice! Thanks for looking into this. Since I had already prepared the fix when filing the issue, I've opened PR #5674 for review. Appreciate it!
Thanks @Dotify71! I had opened PR #5673 earlier with bracket wildcard validation and test coverage across *, ?, [0-9], and [!a-z]. Both PRs address the issue cleanly, so happy for maintainers to review and pick whichever approach they prefer to land!
Activity
axiom-of-choice commentedon Sep 18, 2026
If it's still free, i can take it.
I checked it against main: View(name="custom_name", instrument_name="http_[0-9]") initialises without error, and fnmatchcase then matches both http_1 and http_2, so a named view can match more than one instrument, which is what the spec forbids. The guard at view.py:122 only looks for * and ?. I would extend it to reject [ as well, since fnmatch treats *, ? and [ as the metacharacters, and add a regression test next to test_view_name.
Does that direction work, and are you still planning to open the PR yourself?
Dotify71 commentedon Sep 18, 2026
Hey @somuai @axiom-of-choice! Thanks for looking into this. Since I had already prepared the fix when filing the issue, I've opened PR #5674 for review. Appreciate it!
somuai commentedon Sep 19, 2026
Thanks @Dotify71! I had opened PR #5673 earlier with bracket wildcard validation and test coverage across
*,?,[0-9], and[!a-z]. Both PRs address the issue cleanly, so happy for maintainers to review and pick whichever approach they prefer to land!Dotify71 commentedon Sep 19, 2026
Sounds great, thanks @somuai for contributing! Happy to let the maintainers review both PRs.
fix(sdk): detect character pattern wildcards in View instrument_name (o…