Skip to content

Commit 231765e

Browse files
committed
Addressed comments
1 parent a4394dd commit 231765e

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,14 @@ def _clean_extended_attribute_value(
180180
# Freeze mutable sequences defensively
181181
return tuple(cleaned_seq)
182182

183-
return value
183+
try:
184+
return str(value)
185+
except Exception:
186+
raise TypeError(
187+
f"Invalid type {type(value).__name__} for attribute value. "
188+
f"Expected one of {[valid_type.__name__ for valid_type in _VALID_ANY_VALUE_TYPES]} or a "
189+
"sequence of those types",
190+
)
184191

185192

186193
def _clean_extended_attribute(

opentelemetry-api/tests/attributes/test_attributes.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,5 @@ def __str__(self):
319319
) as clean_extended_attribute_mock:
320320
bdict["request"] = wsgi_request
321321

322-
# Verify that _clean_extended_attribute was called
323-
clean_extended_attribute_mock.assert_called_once()
324-
325-
# Verify that the value passed to _clean_extended_attribute is a string, not the original object
326-
call_args = clean_extended_attribute_mock.call_args
327-
passed_value = call_args[0][1] # Second argument is the value
328-
self.assertIsInstance(passed_value, str)
329-
self.assertNotEqual(
330-
passed_value, original_request
331-
) # Should be stringified, not the original object
332-
self.assertIn(
333-
"DummyWSGIRequest", passed_value
334-
) # String representation includes class name
322+
# Verify that the request stored in the bounded dict matches the cleaned value
323+
self.assertEqual(bdict["request"], "stringified_request")

0 commit comments

Comments
 (0)