-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serde support #576
Comments
I don't believe the spec explicitly requires to provide a serialization formats but rather it leave this questions to each propagator and exporter. I think in some case the serde could make things easier for exporter/propagator writers but usually exporters/propagators need some kind of conversion before serialization. Thus, serde is not a must here. We could provide some supports like using a |
Good question. I'd say we probably don't need it. How does serde support work with backwards compatibility? If we add another field to a struct, which implements I like the idea of a separate crate in case there is demand for serialization and deserialization for some of the types. |
Removed in #738 |
Hi, is there any alternative available right now for this? |
For whoever stumbles on this, I needed to serialize #[derive(Serialize, Deserialize)]
struct SpanContextDef {
trace_id: [u8; 16],
span_id: [u8; 8],
trace_flags: u8,
is_remote: bool,
trace_state: String,
}
// Provide a conversion to construct the remote type.
impl From<SpanContextDef> for SpanContext {
fn from(def: SpanContextDef) -> Self {
SpanContext::new(
TraceId::from_bytes(def.trace_id), SpanId::from_bytes(def.span_id), TraceFlags::new(def.trace_flags), def.is_remote, TraceState::from_str(&def.trace_state).unwrap()
)
}
}
impl From<SpanContext> for SpanContextDef {
fn from(ctx: SpanContext) -> Self {
Self {
trace_id: ctx.trace_id().to_bytes(),
span_id: ctx.span_id().to_bytes(),
trace_flags: ctx.trace_flags().to_u8(),
is_remote: ctx.is_remote(),
trace_state: ctx.trace_state().header()
}
}
}
// In the struct where you need SpanContext
#[serde_as(as = "FromInto<SpanContextDef>")]
SpanContext spanContext See https://docs.rs/serde_with/2.0.1/serde_with/guide/serde_as_transformations/index.html#convert-to-an-intermediate-type-using-into for more details about serde_with |
I've been actively using this, and was surprised to find that it had disappeared when I upgraded opentelemetry. I'd love to register interest in this feature returning in the future, if at all possible. |
I think providing |
@jtescher I've been using it to both serialize and deserialize |
Yep that's included in what I was referring to, I think we could support that. |
@jtescher Thank you! |
@jtescher Checking back in on this. Would it be possible to get serde support for |
(I should have searched closed issues first, but stumbled upon this after starting to work on #1074, which I just opened.) |
Should the core
opentelemetry
crate support serde? There are standard serialization formats, it's unclear that this is necessary (or compliant with the intention of the spec).The text was updated successfully, but these errors were encountered: