Skip to content

API coerces byte-valued attributes to strings #4460

@dimaqq

Description

@dimaqq

Describe your environment

OS: any
Python version: any
SDK version: 1.30.0
API version: 1.30.0

What happened?

OTLP proto was expanded to allow for bytes values in attributes about 3 years ago.

#4118 / #4128 implemented that in the OTLP exporter.

Unfortunately, the #4218 alone is not enough.

The bytes-valued attributes are coerced to strings way before they reach the exporter.

It happens here:

def _clean_attribute_value(
value: types.AttributeValue, limit: Optional[int]
) -> Optional[types.AttributeValue]:
if value is None:
return None
if isinstance(value, bytes):
try:
value = value.decode()
except UnicodeDecodeError:
_logger.warning("Byte attribute could not be decoded.")
return None

Steps to Reproduce

  • set attribute with bytes value that is internally string-safe
  • export
  • see stringValue instead of bytesValue in the output

Expected Result

produces bytesValue: <bytes>

Actual Result

produces stringValue: <str> or drops the attribute with a warning

Additional context

#4118 added encoding of bytes attributes in OTLP

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions