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:
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 aBoundedAttributes
, but its type is declared astypes.Attributes
, i.e.Optional[Mapping[str, AttributeValue]]
. This means thatevent.attributes
could easily be another mapping such asdict
or evenNone
in which case trying to access.dropped
raisesAttributeError
.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 toReadableSpan.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 customSpanProcessor
.