Skip to content

Commit 96fa8af

Browse files
committed
Allow instrument names to have '/' and up to 255 characters
Fixes #3431
1 parent ae42ad1 commit 96fa8af

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
([#3335](https://github.com/open-telemetry/opentelemetry-python/pull/3335))
1212
- Fix error when no LoggerProvider configured for LoggingHandler
1313
([#3423](https://github.com/open-telemetry/opentelemetry-python/pull/3423))
14+
- Allow instrument names to have '/' and up to 255 characters
15+
([#3442](https://github.com/open-telemetry/opentelemetry-python/pull/3442))
1416

1517

1618
## Version 1.20.0/0.41b0 (2023-09-04)

opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
_logger = getLogger(__name__)
4040

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

4444

opentelemetry-api/tests/metrics/test_instruments.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,13 @@ def test_observable_up_down_counter_callback(self):
564564
)
565565

566566
def test_name_check(self):
567-
568567
instrument = ChildInstrument("name")
569568

570569
self.assertEqual(
571570
instrument._check_name_unit_description(
572-
"a" * 63, "unit", "description"
571+
"a" * 255, "unit", "description"
573572
)["name"],
574-
"a" * 63,
573+
"a" * 255,
575574
)
576575
self.assertEqual(
577576
instrument._check_name_unit_description(
@@ -591,12 +590,25 @@ def test_name_check(self):
591590
)["name"],
592591
"a_",
593592
)
593+
self.assertEqual(
594+
instrument._check_name_unit_description(
595+
"a/", "unit", "description"
596+
)["name"],
597+
"a/",
598+
)
594599

595-
self.assertIsNone(
600+
# the old max length
601+
self.assertIsNotNone(
596602
instrument._check_name_unit_description(
597603
"a" * 64, "unit", "description"
598604
)["name"]
599605
)
606+
self.assertIsNone(
607+
instrument._check_name_unit_description(
608+
"a" * 256, "unit", "description"
609+
)["name"]
610+
)
611+
600612
self.assertIsNone(
601613
instrument._check_name_unit_description(
602614
"Ñ", "unit", "description"
@@ -619,7 +631,6 @@ def test_name_check(self):
619631
)
620632

621633
def test_unit_check(self):
622-
623634
instrument = ChildInstrument("name")
624635

625636
self.assertEqual(
@@ -653,7 +664,6 @@ def test_unit_check(self):
653664
)
654665

655666
def test_description_check(self):
656-
657667
instrument = ChildInstrument("name")
658668

659669
self.assertEqual(

0 commit comments

Comments
 (0)