Skip to content

Commit

Permalink
Do not count invalid attributes for dropped (#2096)
Browse files Browse the repository at this point in the history
Do not count invalid attributes for dropped


Co-authored-by: Owais Lone <owais@users.noreply.github.com>
  • Loading branch information
srikanthccv and owais authored Sep 9, 2021
1 parent 08392c8 commit df76b62
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `opentelemetry-semantic-conventions` Update to semantic conventions v1.6.1
([#2077](https://github.com/open-telemetry/opentelemetry-python/pull/2077))
- Do not count invalid attributes for dropped
([#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))

Expand Down
14 changes: 8 additions & 6 deletions opentelemetry-api/src/opentelemetry/attributes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@ def __setitem__(self, key, value):
self.dropped += 1
return

if key in self._dict:
del self._dict[key]
elif self.maxlen is not None and len(self._dict) == self.maxlen:
del self._dict[next(iter(self._dict.keys()))]
self.dropped += 1

value = _clean_attribute(key, value, self.max_value_len)
if value is not None:
if key in self._dict:
del self._dict[key]
elif (
self.maxlen is not None and len(self._dict) == self.maxlen
):
self._dict.popitem(last=False)
self.dropped += 1

self._dict[key] = value

def __delitem__(self, key):
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-api/tests/attributes/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def test_bounded_dict(self):

self.assertEqual(len(bdict), dic_len)
self.assertEqual(bdict.dropped, dic_len)
# Invalid values shouldn't be considered for `dropped`
bdict["invalid-seq"] = [None, 1, "2"]
self.assertEqual(bdict.dropped, dic_len)

# test that elements in the dict are the new ones
for key in self.base:
Expand Down

0 comments on commit df76b62

Please sign in to comment.