Skip to content

Commit ae4f570

Browse files
committed
Fail if key is empty.
1 parent 938a0b3 commit ae4f570

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __new__(cls, value: str) -> "EntryKey":
4949

5050
@staticmethod
5151
def create(value: str) -> "EntryKey":
52-
if len(value) > 255 or any(c not in PRINTABLE for c in value):
52+
if not 0 < len(value) <= 255 or any(c not in PRINTABLE for c in value):
5353
raise ValueError("Invalid EntryKey", value)
5454

5555
return typing.cast(EntryKey, value)

opentelemetry-api/tests/distributedcontext/test_distributed_context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def test_entry_ttl_unlimited_propagation(self):
3232

3333

3434
class TestEntryKey(unittest.TestCase):
35+
def test_create_empty(self):
36+
with self.assertRaises(ValueError):
37+
distributedcontext.EntryKey.create("")
38+
3539
def test_create_too_long(self):
3640
with self.assertRaises(ValueError):
3741
distributedcontext.EntryKey.create("a" * 256)

0 commit comments

Comments
 (0)