Skip to content

ConsoleLogExporter with bytes in body fails #4606

Closed
@aabmass

Description

@aabmass

Describe your environment

No response

What happened?

When exporting a log with bytes in the body, the exporter fails with TypeError: Object of type bytes is not JSON serializable when trying to json.dumps() it.

Steps to Reproduce

from time import time_ns
from opentelemetry.sdk._logs.export import ConsoleLogExporter
from opentelemetry.sdk._logs import LogData, LogRecord
from opentelemetry.sdk.util.instrumentation import InstrumentationScope

exporter = ConsoleLogExporter()
exporter.export(
    [
        LogData(
            instrumentation_scope=InstrumentationScope(name="foo"),
            log_record=LogRecord(timestamp=time_ns(), body={"foo": b"bar"}),
        )
    ]
)

Expected Result

bytes are a valid AnyValue so it should be encoded and exported properly. Check the specification for details.

Actual Result

TypeError: Object of type bytes is not JSON serializable

Additional context

No response

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions