Skip to content

Commit

Permalink
Add support to type bytes for OTLP AnyValue encoding (#4128)
Browse files Browse the repository at this point in the history
  • Loading branch information
wasup-yash committed Aug 28, 2024
1 parent ea36c5d commit 15ea441
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -80,6 +81,10 @@ def test_encode_attributes_all_kinds(self):
)
),
),
PB2KeyValue(
key="binary_data",
value=PB2AnyValue(bytes_value=b"x00\x01\x02"),
),
],
)

Expand Down

0 comments on commit 15ea441

Please sign in to comment.