Skip to content

Commit

Permalink
Allow instrument names to have '/' and up to 255 characters (#3442)
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed Sep 19, 2023
1 parent 6973de2 commit 647fbc7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3423](https://github.com/open-telemetry/opentelemetry-python/pull/3423))
- Make `opentelemetry_metrics_exporter` entrypoint support pull exporters
([#3428](https://github.com/open-telemetry/opentelemetry-python/pull/3428))
- 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
19 changes: 15 additions & 4 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,24 @@ 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 Down

0 comments on commit 647fbc7

Please sign in to comment.