open-telemetry / opentelemetry-python

OpenTelemetry Python API and SDK
https://opentelemetry.io
Apache License 2.0
1.67k stars 571 forks source link

OTLP exporter is encoding invalid span/trace IDs in the logs #3828

Open yurishkuro opened 3 months ago

yurishkuro commented 3 months ago

Describe your environment Using v1.23.0, configured OTLP HTTP exporter for logs

Steps to reproduce Running a sample code that roughly looks like https://github.com/open-telemetry/opentelemetry-python/blob/main/docs/examples/logs/example.py

What is the expected behavior? When there is no active trace, the exporter should not be including trace/span IDs into Protobuf messages

What is the actual behavior? When I serialize received protobuf to JSON it looks like this:

              "traceId": "AAAAAAAAAAAAAAAAAAAAAA==",
              "spanId": "AAAAAAAAAAA="

That means the exporter is sending 00....00 bytes as trace and span IDs. The zero values indicate invalid trace/span ID, and the fields in the protobuf are optional, so the right behavior would be to not include these fields in the output. This will also minimize the size of the exported messages.

If maintainers agree with this, I can create a PR.