Skip to content

Commit 15ea441

Browse files
authored
Add support to type bytes for OTLP AnyValue encoding (#4128)
1 parent ea36c5d commit 15ea441

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
([#4103](https://github.com/open-telemetry/opentelemetry-python/pull/4103))
2828
- Update semantic conventions to version 1.27.0
2929
([#4104](https://github.com/open-telemetry/opentelemetry-python/pull/4104))
30+
- Add support to type bytes for OTLP AnyValue
31+
([#4128](https://github.com/open-telemetry/opentelemetry-python/pull/4128))
3032
- Export ExponentialHistogram and ExponentialHistogramDataPoint
3133
([#4134](https://github.com/open-telemetry/opentelemetry-python/pull/4134))
3234
- Implement Client Key and Certificate File Support for All OTLP Exporters

Diff for: exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def _encode_value(value: Any) -> PB2AnyValue:
7575
return PB2AnyValue(int_value=value)
7676
if isinstance(value, float):
7777
return PB2AnyValue(double_value=value)
78+
if isinstance(value, bytes):
79+
return PB2AnyValue(bytes_value=value)
7880
if isinstance(value, Sequence):
7981
return PB2AnyValue(
8082
array_value=PB2ArrayValue(values=[_encode_value(v) for v in value])

Diff for: exporter/opentelemetry-exporter-otlp-proto-common/tests/test_attribute_encoder.py

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_encode_attributes_all_kinds(self):
3636
"greet": ["hola", "bonjour"], # Sequence[str]
3737
"data": [1, 2], # Sequence[int]
3838
"data_granular": [1.4, 2.4], # Sequence[float]
39+
"binary_data": b"x00\x01\x02", # bytes
3940
}
4041
)
4142
self.assertEqual(
@@ -80,6 +81,10 @@ def test_encode_attributes_all_kinds(self):
8081
)
8182
),
8283
),
84+
PB2KeyValue(
85+
key="binary_data",
86+
value=PB2AnyValue(bytes_value=b"x00\x01\x02"),
87+
),
8388
],
8489
)
8590

0 commit comments

Comments
 (0)