Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit and name regexes #2796

Merged
merged 2 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.12.0rc1-0.31b0...HEAD)

- Fix instrument name and unit regexes
([#2796](https://github.com/open-telemetry/opentelemetry-python/pull/2796))
- Add optional sessions parameter to all Exporters leveraging requests.Session
([#2783](https://github.com/open-telemetry/opentelemetry-python/pull/2783))
([#2783](https://github.com/open-telemetry/opentelemetry-python/pull/2783))
- Add min/max fields to Histogram
([#2759](https://github.com/open-telemetry/opentelemetry-python/pull/2759))
- `opentelemetry-exporter-otlp-proto-http` Add support for OTLP/HTTP log exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass
from logging import getLogger
from re import ASCII
from re import compile as re_compile
from typing import (
Callable,
Expand All @@ -39,8 +38,8 @@

_logger = getLogger(__name__)

_name_regex = re_compile(r"[a-zA-Z][-.\w]{0,62}", ASCII)
_unit_regex = re_compile(r"\w{0,63}", ASCII)
_name_regex = re_compile(r"[a-zA-Z][-_.a-zA-Z0-9]{0,62}")
_unit_regex = re_compile(r"[\x00-\x7F]{0,63}")


@dataclass(frozen=True)
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-api/tests/metrics/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ def test_name_regex(self):
self.assertTrue(instrument._check_name_and_unit("a.", "unit")[0])
self.assertTrue(instrument._check_name_and_unit("a-", "unit")[0])
self.assertTrue(instrument._check_name_and_unit("a_", "unit")[0])

self.assertFalse(instrument._check_name_and_unit("a" * 64, "unit")[0])
self.assertFalse(instrument._check_name_and_unit("Ñ", "unit")[0])
self.assertFalse(instrument._check_name_and_unit("_a", "unit")[0])
Expand All @@ -582,5 +583,7 @@ def test_unit_regex(self):
instrument = ChildInstrument("name")

self.assertTrue(instrument._check_name_and_unit("name", "a" * 63)[1])
self.assertTrue(instrument._check_name_and_unit("name", "{a}")[1])

self.assertFalse(instrument._check_name_and_unit("name", "a" * 64)[1])
self.assertFalse(instrument._check_name_and_unit("name", "Ñ")[1])