From 09faf57076066bc0ac7f0da0218c739ca876c581 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sun, 5 Sep 2021 11:15:34 +0530 Subject: [PATCH 1/2] Do not skip sequence attribute on decode error --- .../src/opentelemetry/attributes/__init__.py | 6 +----- .../tests/attributes/test_attributes.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/attributes/__init__.py b/opentelemetry-api/src/opentelemetry/attributes/__init__.py index a266839326a..bdc844f3e26 100644 --- a/opentelemetry-api/src/opentelemetry/attributes/__init__.py +++ b/opentelemetry-api/src/opentelemetry/attributes/__init__.py @@ -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) diff --git a/opentelemetry-api/tests/attributes/test_attributes.py b/opentelemetry-api/tests/attributes/test_attributes.py index fa0606b347c..0c374d28d5f 100644 --- a/opentelemetry-api/tests/attributes/test_attributes.py +++ b/opentelemetry-api/tests/attributes/test_attributes.py @@ -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( From 94390ab637d5b7476113958a9926617801558b15 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sun, 5 Sep 2021 11:18:13 +0530 Subject: [PATCH 2/2] Add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bee8bd3cca..06a53977128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#2077](https://github.com/open-telemetry/opentelemetry-python/pull/2077)) - 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