Skip to content

Commit

Permalink
Do not skip sequence attribute on decode error (#2097)
Browse files Browse the repository at this point in the history
Do not skip sequence attribute on decode error

Co-authored-by: Owais Lone <owais@users.noreply.github.com>
  • Loading branch information
srikanthccv and owais authored Sep 10, 2021
1 parent df76b62 commit df1f842
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2096](https://github.com/open-telemetry/opentelemetry-python/pull/2096))
- Fix propagation bug caused by counting skipped entries
([#2071](https://github.com/open-telemetry/opentelemetry-python/pull/2071))
- Do not skip sequence attribute on decode error
([#2097](https://github.com/open-telemetry/opentelemetry-python/pull/2097))

## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26

Expand Down
6 changes: 1 addition & 5 deletions opentelemetry-api/src/opentelemetry/attributes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ def _clean_attribute(
cleaned_seq = []

for element in value:
# None is considered valid in any sequence
if element is None:
cleaned_seq.append(element)

element = _clean_attribute_value(element, max_len)
# reject invalid elements
if element is None:
cleaned_seq.append(element)
continue

element_type = type(element)
Expand Down
19 changes: 19 additions & 0 deletions opentelemetry-api/tests/attributes/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ def test_clean_attribute(self):
self.assertInvalid("value", "")
self.assertInvalid("value", None)

def test_sequence_attr_decode(self):
seq = [
None,
b"Content-Disposition",
b"Content-Type",
b"\x81",
b"Keep-Alive",
]
expected = [
None,
"Content-Disposition",
"Content-Type",
None,
"Keep-Alive",
]
self.assertEqual(
_clean_attribute("headers", seq, None), tuple(expected)
)


class TestBoundedAttributes(unittest.TestCase):
base = collections.OrderedDict(
Expand Down

0 comments on commit df1f842

Please sign in to comment.