diff --git a/CHANGELOG.md b/CHANGELOG.md index 50db7d0bd03..bf7db9c04ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py b/opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py index fec2879ef6c..54b2fb7597e 100644 --- a/opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py +++ b/opentelemetry-api/src/opentelemetry/metrics/_internal/instrument.py @@ -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}") diff --git a/opentelemetry-api/tests/metrics/test_instruments.py b/opentelemetry-api/tests/metrics/test_instruments.py index 4a3d3d448b3..e66460de354 100644 --- a/opentelemetry-api/tests/metrics/test_instruments.py +++ b/opentelemetry-api/tests/metrics/test_instruments.py @@ -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( @@ -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"