open-telemetry / opentelemetry-python

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

`_encode_events` assumes that `event.attributes.dropped` exists #3761

Closed alexmojaki closed 3 months ago

alexmojaki commented 7 months ago

This line:

https://github.com/open-telemetry/opentelemetry-python/blob/8ad10f7d8fd59be49f3d2e683824ff921c0781f8/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py#L139

is essentially assuming that event.attributes is a BoundedAttributes, but its type is declared as types.Attributes, i.e. Optional[Mapping[str, AttributeValue]]. This means that event.attributes could easily be another mapping such as dict or even None in which case trying to access .dropped raises AttributeError.

Just above in the same file is an example of one good way to solve this:

https://github.com/open-telemetry/opentelemetry-python/blob/8ad10f7d8fd59be49f3d2e683824ff921c0781f8/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py#L122

i.e. a property Event.dropped_attributes identical to ReadableSpan.dropped_attributes could be created.

For context, I encountered this problem while creating modified copies of Event objects in which sensitive data is removed in a custom SpanProcessor.

soumyadeepm04 commented 3 months ago

Hello, if no one is working on this, could I have a go at it?

pmcollins commented 3 months ago

Please feel free @soumyadeepm04 if you are still interested.