Skip to content

Commit ca20cd0

Browse files
committed
Add explaination for try-catch
1 parent 7e6aad7 commit ca20cd0

File tree

1 file changed

+5
-0
lines changed
  • opentelemetry-api/src/opentelemetry/attributes

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ def _clean_extended_attribute_value( # pylint: disable=too-many-branches
180180
# Freeze mutable sequences defensively
181181
return tuple(cleaned_seq)
182182

183+
# Some applications such as Django add values to log records whose types fall outside the
184+
# primitive types and `_VALID_ANY_VALUE_TYPES`, i.e., they are not of type `AnyValue`.
185+
# Rather than attempt to whitelist every possible instrumentation, we stringify those values here
186+
# so they can still be represented as attributes, falling back to the original TypeError only if
187+
# converting to string raises.
183188
try:
184189
return str(value)
185190
except Exception:

0 commit comments

Comments
 (0)