Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not count invalid attributes for dropped #2096

Merged
merged 4 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
):
self._dict.popitem(last=False)
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
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