-
Notifications
You must be signed in to change notification settings - Fork 829
Description
Feature Request
Crates
tracing-serde
Motivation
Currently, tracing-serde
supports serializing tracing
types, such as Metadata
, Event
, span::Attributes
and span::Record
, etc. However, it does not support deserializing those types from a serialized representation. It would be good to support this.
Proposal
We should add structs to tracing-serde
that represent the deserialized form of tracing
types that can currently be serialized. These would have public accessors returning the fields of those types, and implement the serde::Deserialize
trait.
Alternatives
From the outside, it might seem like we should just implement serde::Deserialize
for tracing-core
types like Metadata
, Event
, et cetera, rather than adding new structs that those types can be deserialized as. However, there are some serious issues with this. tracing
structs like Event
and Metadata
consist primarily of references to other data for performance and space optimization reasons. Similarly to how we don't serialize the internal representations of types like ValueSet
and instead use SerializeMap
etc, we wouldn't want to deserialize internal representations that don't make sense outside of the address space of the process where they originated.
Another option is to not implement Deserialize
for any structs, and just change all Serialize
implementations to serialize data structures like maps and sets. This would mean removing all uses of SerializeStruct
and replacing it with unstructured data. However, this makes using deserialized tracing data more difficult for users, as rather than having a nice structured API for well-known fields, everything is represented as unstructured maps that may or may not contain particular values or types.