From fa43ff464a3285a706a4dc761579bf6428f30e5f Mon Sep 17 00:00:00 2001 From: Aleksander Heintz Date: Tue, 6 Feb 2024 21:11:46 +0100 Subject: [PATCH 1/2] make binary propagator take byte slice instead of vec --- .../src/trace/propagator/binary/base64_format.rs | 2 +- .../src/trace/propagator/binary/binary_propagator.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/opentelemetry-contrib/src/trace/propagator/binary/base64_format.rs b/opentelemetry-contrib/src/trace/propagator/binary/base64_format.rs index 45712b5e..07fde1b7 100644 --- a/opentelemetry-contrib/src/trace/propagator/binary/base64_format.rs +++ b/opentelemetry-contrib/src/trace/propagator/binary/base64_format.rs @@ -32,7 +32,7 @@ where fn deserialize_from_base64(&self, base64: &str) -> SpanContext { if let Ok(bytes) = decode(base64.as_bytes()) { - self.deserialize_from_bytes(bytes) + self.deserialize_from_bytes(&bytes) } else { SpanContext::empty_context() } diff --git a/opentelemetry-contrib/src/trace/propagator/binary/binary_propagator.rs b/opentelemetry-contrib/src/trace/propagator/binary/binary_propagator.rs index 2f8eba73..a56df6d6 100644 --- a/opentelemetry-contrib/src/trace/propagator/binary/binary_propagator.rs +++ b/opentelemetry-contrib/src/trace/propagator/binary/binary_propagator.rs @@ -15,7 +15,7 @@ pub trait BinaryFormat { fn serialize_into_bytes(&self, context: &SpanContext) -> [u8; 29]; /// Deserializes a span context from a byte array. - fn deserialize_from_bytes(&self, bytes: Vec) -> SpanContext; + fn deserialize_from_bytes(&self, bytes: &[u8]) -> SpanContext; } /// Extracts and injects `SpanContext`s from byte arrays. @@ -46,7 +46,7 @@ impl BinaryFormat for BinaryPropagator { } /// Deserializes a span context from a byte array. - fn deserialize_from_bytes(&self, bytes: Vec) -> SpanContext { + fn deserialize_from_bytes(&self, bytes: &[u8]) -> SpanContext { if bytes.is_empty() { return SpanContext::empty_context(); } @@ -172,7 +172,7 @@ mod tests { let propagator = BinaryPropagator::new(); for (context, data) in from_bytes_data() { - assert_eq!(propagator.deserialize_from_bytes(data), context) + assert_eq!(propagator.deserialize_from_bytes(&data), context) } } } From ca3709b7367bf6fbf8da20b8dd16b8ff4116a6ca Mon Sep 17 00:00:00 2001 From: Aleksander Heintz Date: Tue, 6 Feb 2024 21:15:48 +0100 Subject: [PATCH 2/2] update changelog --- opentelemetry-contrib/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opentelemetry-contrib/CHANGELOG.md b/opentelemetry-contrib/CHANGELOG.md index d9425346..61fdaf13 100644 --- a/opentelemetry-contrib/CHANGELOG.md +++ b/opentelemetry-contrib/CHANGELOG.md @@ -2,6 +2,10 @@ ## vNext +### Changed + +- Update `BinaryFormat::deserialize_from_bytes` to take a byte slice instead of a Vec [#32](https://github.com/open-telemetry/opentelemetry-rust-contrib/pull/32) + ## v0.13.0 ### Changed