Skip to content

Commit 0f3cf3d

Browse files
committed
Addressed feedback
1 parent 769c606 commit 0f3cf3d

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ def __setitem__(self, key: str, value: types.AnyValue) -> None:
282282
return
283283

284284
if self._extended_attributes:
285-
# Convert types other than AnyValue to strings before cleaning
286-
if not isinstance(value, _VALID_ANY_VALUE_TYPES):
287-
value = str(value)
288285
value = _clean_extended_attribute(
289286
key, value, self.max_value_len
290287
)

opentelemetry-api/tests/attributes/test_attributes.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,20 +303,18 @@ def test_extended_attributes(self):
303303
clean_extended_attribute_mock.assert_called_once()
304304

305305
def test_wsgi_request_conversion_to_string(self):
306-
"""Test that WSGI request objects are converted to strings before calling _clean_extended_attribute."""
306+
"""Test that WSGI request objects are converted to strings when _clean_extended_attribute is called."""
307307

308308
class DummyWSGIRequest:
309309
def __str__(self):
310310
return "<DummyWSGIRequest method=GET path=/example/>"
311311

312-
bdict = BoundedAttributes(extended_attributes=True, immutable=False)
313312
wsgi_request = DummyWSGIRequest()
314313

315-
with unittest.mock.patch(
316-
"opentelemetry.attributes._clean_extended_attribute",
317-
return_value="stringified_request",
318-
):
319-
bdict["request"] = wsgi_request
314+
cleaned_value = _clean_extended_attribute(
315+
"request", wsgi_request, None
316+
)
320317

321-
# Verify that the request stored in the bounded dict matches the cleaned value
322-
self.assertEqual(bdict["request"], "stringified_request")
318+
# Verify we get a string back from the cleaner
319+
self.assertIsInstance(cleaned_value, str)
320+
self.assertEqual("<DummyWSGIRequest method=GET path=/example/>", cleaned_value)

0 commit comments

Comments
 (0)