chore: implement serde for SpanContext#155
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements serde Serialize and Deserialize traits for the SpanContext struct, enabling JSON and other serialization formats. The implementation leverages the existing W3C Trace Context traceparent encoding format for serialization, ensuring compatibility with distributed tracing standards.
Key Changes
- Added
Serializeimplementation that encodes SpanContext as a W3C traceparent string - Added
Deserializeimplementation that decodes from a W3C traceparent string format - Error handling for invalid traceparent strings during deserialization
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fastrace/src/collector/id.rs
Outdated
| impl<'a> serde::Deserialize<'a> for SpanContext { | ||
| fn deserialize<D: serde::Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> { |
There was a problem hiding this comment.
The lifetime parameter name 'a' is inconsistent with the conventional 'de' used in other Deserialize implementations in this file (see TraceId at line 54 and SpanId at line 119). Using 'de' (short for "deserializer") is the Rust community convention for Deserialize implementations and makes the code more consistent.
| impl<'a> serde::Deserialize<'a> for SpanContext { | |
| fn deserialize<D: serde::Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> { | |
| impl<'de> serde::Deserialize<'de> for SpanContext { | |
| fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { |
No description provided.