Skip to content

Commit 12fe4c9

Browse files
authored
Do not check every string character (#1942)
1 parent da16df0 commit 12fe4c9

File tree

1 file changed

+12
-13
lines changed
  • opentelemetry-api/src/opentelemetry/attributes

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import threading
1818
from collections import OrderedDict
1919
from collections.abc import MutableMapping
20-
from types import MappingProxyType
2120
from typing import MutableSequence, Optional, Sequence
2221

2322
from opentelemetry.util import types
@@ -38,9 +37,10 @@ def _is_valid_attribute_value(value: types.AttributeValue) -> bool:
3837
i.e. it MUST NOT contain values of different types.
3938
"""
4039

40+
if isinstance(value, _VALID_ATTR_VALUE_TYPES):
41+
return True
42+
4143
if isinstance(value, Sequence):
42-
if len(value) == 0:
43-
return True
4444

4545
sequence_first_valid_type = None
4646
for element in value:
@@ -69,16 +69,15 @@ def _is_valid_attribute_value(value: types.AttributeValue) -> bool:
6969
type(element).__name__,
7070
)
7171
return False
72-
73-
elif not isinstance(value, _VALID_ATTR_VALUE_TYPES):
74-
_logger.warning(
75-
"Invalid type %s for attribute value. Expected one of %s or a "
76-
"sequence of those types",
77-
type(value).__name__,
78-
[valid_type.__name__ for valid_type in _VALID_ATTR_VALUE_TYPES],
79-
)
80-
return False
81-
return True
72+
return True
73+
74+
_logger.warning(
75+
"Invalid type %s for attribute value. Expected one of %s or a "
76+
"sequence of those types",
77+
type(value).__name__,
78+
[valid_type.__name__ for valid_type in _VALID_ATTR_VALUE_TYPES],
79+
)
80+
return False
8281

8382

8483
def _filter_attributes(attributes: types.Attributes) -> None:

0 commit comments

Comments
 (0)