diff --git a/CHANGELOG.md b/CHANGELOG.md index 516b10c2aa5..4a1e279a4cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#4103](https://github.com/open-telemetry/opentelemetry-python/pull/4103)) - Update semantic conventions to version 1.27.0 ([#4104](https://github.com/open-telemetry/opentelemetry-python/pull/4104)) +- Add support to type bytes for OTLP AnyValue + ([#4128](https://github.com/open-telemetry/opentelemetry-python/pull/4128)) - Export ExponentialHistogram and ExponentialHistogramDataPoint ([#4134](https://github.com/open-telemetry/opentelemetry-python/pull/4134)) - Implement Client Key and Certificate File Support for All OTLP Exporters diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py index 23bc23822c4..65f94771407 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py @@ -75,6 +75,8 @@ def _encode_value(value: Any) -> PB2AnyValue: return PB2AnyValue(int_value=value) if isinstance(value, float): return PB2AnyValue(double_value=value) + if isinstance(value, bytes): + return PB2AnyValue(bytes_value=value) if isinstance(value, Sequence): return PB2AnyValue( array_value=PB2ArrayValue(values=[_encode_value(v) for v in value]) diff --git a/exporter/opentelemetry-exporter-otlp-proto-common/tests/test_attribute_encoder.py b/exporter/opentelemetry-exporter-otlp-proto-common/tests/test_attribute_encoder.py index 01856611036..c7e4dbc843a 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-common/tests/test_attribute_encoder.py +++ b/exporter/opentelemetry-exporter-otlp-proto-common/tests/test_attribute_encoder.py @@ -36,6 +36,7 @@ def test_encode_attributes_all_kinds(self): "greet": ["hola", "bonjour"], # Sequence[str] "data": [1, 2], # Sequence[int] "data_granular": [1.4, 2.4], # Sequence[float] + "binary_data": b"x00\x01\x02", # bytes } ) self.assertEqual( @@ -80,6 +81,10 @@ def test_encode_attributes_all_kinds(self): ) ), ), + PB2KeyValue( + key="binary_data", + value=PB2AnyValue(bytes_value=b"x00\x01\x02"), + ), ], )