Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df76b62

Browse files
srikanthccvowais
andauthored
Do not count invalid attributes for dropped (open-telemetry#2096)
Do not count invalid attributes for dropped Co-authored-by: Owais Lone <[email protected]>
1 parent 08392c8 commit df76b62

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
- `opentelemetry-semantic-conventions` Update to semantic conventions v1.6.1
1010
([#2077](https://github.com/open-telemetry/opentelemetry-python/pull/2077))
11+
- Do not count invalid attributes for dropped
12+
([#2096](https://github.com/open-telemetry/opentelemetry-python/pull/2096))
1113
- Fix propagation bug caused by counting skipped entries
1214
([#2071](https://github.com/open-telemetry/opentelemetry-python/pull/2071))
1315

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,16 @@ def __setitem__(self, key, value):
172172
self.dropped += 1
173173
return
174174

175-
if key in self._dict:
176-
del self._dict[key]
177-
elif self.maxlen is not None and len(self._dict) == self.maxlen:
178-
del self._dict[next(iter(self._dict.keys()))]
179-
self.dropped += 1
180-
181175
value = _clean_attribute(key, value, self.max_value_len)
182176
if value is not None:
177+
if key in self._dict:
178+
del self._dict[key]
179+
elif (
180+
self.maxlen is not None and len(self._dict) == self.maxlen
181+
):
182+
self._dict.popitem(last=False)
183+
self.dropped += 1
184+
183185
self._dict[key] = value
184186

185187
def __delitem__(self, key):

opentelemetry-api/tests/attributes/test_attributes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def test_bounded_dict(self):
137137

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

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

0 commit comments

Comments
 (0)