Skip to content

Commit

Permalink
Allow instrument names to have '/' and up to 255 characters
Browse files Browse the repository at this point in the history
Fixes #3431
  • Loading branch information
aabmass committed Sep 15, 2023
1 parent 3a651c7 commit 5477c20
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3335](https://github.com/open-telemetry/opentelemetry-python/pull/3335))
- Fix error when no LoggerProvider configured for LoggingHandler
([#3423](https://github.com/open-telemetry/opentelemetry-python/pull/3423))
- Allow instrument names to have '/' and up to 255 characters
([#3442](https://github.com/open-telemetry/opentelemetry-python/pull/3442))


## Version 1.20.0/0.41b0 (2023-09-04)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

_logger = getLogger(__name__)

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


Expand Down
22 changes: 16 additions & 6 deletions opentelemetry-api/tests/metrics/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,13 @@ def test_observable_up_down_counter_callback(self):
)

def test_name_check(self):

instrument = ChildInstrument("name")

self.assertEqual(
instrument._check_name_unit_description(
"a" * 63, "unit", "description"
"a" * 255, "unit", "description"
)["name"],
"a" * 63,
"a" * 255,
)
self.assertEqual(
instrument._check_name_unit_description(
Expand All @@ -591,12 +590,25 @@ def test_name_check(self):
)["name"],
"a_",
)
self.assertEqual(
instrument._check_name_unit_description(
"a/", "unit", "description"
)["name"],
"a/",
)

self.assertIsNone(
# the old max length
self.assertIsNotNone(
instrument._check_name_unit_description(
"a" * 64, "unit", "description"
)["name"]
)
self.assertIsNone(
instrument._check_name_unit_description(
"a" * 256, "unit", "description"
)["name"]
)

self.assertIsNone(
instrument._check_name_unit_description(
"Ñ", "unit", "description"
Expand All @@ -619,7 +631,6 @@ def test_name_check(self):
)

def test_unit_check(self):

instrument = ChildInstrument("name")

self.assertEqual(
Expand Down Expand Up @@ -653,7 +664,6 @@ def test_unit_check(self):
)

def test_description_check(self):

instrument = ChildInstrument("name")

self.assertEqual(
Expand Down

0 comments on commit 5477c20

Please sign in to comment.