Comments (4)
I'd like to take a shot at it!
from tracing.
I've been struggling a bit getting this issue done & I've talked with Eliza out of band about it. I thought I would go ahead & push up some of my work on this issue on my fork. Maybe some other folks have ideas about how we can get serde
compatability.
The problem I'm running into is how exactly to implement Visit
. All the Serializer
methods consume self
by-value but the Visit
methods take &mut self
. Another issue is that all the serde
methods return Result
& tokio-trace
returns ()
. That makes it so we have to unwrap
all the values. What makes sense to proceed on this issue? Do you have any thoughts @LucioFranco?
https://github.com/DebugSteven/tokio-trace-nursery/tree/tokio-trace-serde
from tracing.
@DebugSteven hmm, I took a look, I'm not sure I understand where the issue is with Serializer
consuming self? Could you point out where you are seeing this issue?
I think for the second option, we probably just want to drop the field maybe? Serde can fail since its more general but in a logging/tracing context, it makes sense for it to not fail since im not sure what you'd do with the failed data? We prob dont want to log the error either since that will get noisy.
from tracing.
The problem I'm running into is how exactly to implement
Visit
. All theSerializer
methods consumeself
by-value but theVisit
methods take&mut self
.
When serializing something that implements Visit
, you're probably going to be using a SerializeMap
rather than a Serializer
, since we want to record fields as map key/value pairs. SerializeMap
's serialize functions take &mut self
.
Another issue is that all the
serde
methods returnResult
&tokio-trace
returns()
. That makes it so we have tounwrap
all the values. What makes sense to proceed on this issue?
I'd probably recommend something like this (note that this is just a sketch):
struct SerdeVisitor<S: SerializeMap> {
serializer: S,
state: Result<(), S::Error>
}
impl<S: SerializeMap> Visit for SerdeVisitor<S> {
fn record_bool(&mut self, field: &Field, value: bool) {
// If previous fields serialized successfully, continue serializing,
// otherwise, short-circuit and do nothing.
if self.state.is_ok() {
self.state = self.serializer
.serialize_entry(field.name(), value)
.map(|_| ());
}
}
// ...
}
impl<S: SerializeMap> SerdeVisitor<S> {
/// Completes serializing the visited object, returning `Ok(())` if all
/// fields were serialized correctly, or `Err(S::Error)` if a field could
/// not be serialized.
fn finish(self) -> Result<S::Ok, S::Error> {
self.state?;
self.serializer.end()
}
}
One other thing: after speaking to you a bit out of band, I realised something important that I don't think I made clear enough in the original issue description. In most cases, the right way to implement serialization is to try and serialize all the data exactly as it's represented in process, so that the same representation can be reconstructed. That's not what we want to do here --- tokio-trace
has a lot of fairly complex types with complex relationships for performance reasons, but those often map to much simpler concepts. For example, the Field
type is internally represented as a callsite ID and an index to a static string in an array. The general approach would be to serialize the index and callsite ID, so the same Field
struct can be reconstructed. Instead, though, we want to serialize the string returned by calling "name" on the Field
--- we don't want to expose these internal representation details that are in most cases the result of performance optimizations. Similarly, a ValueSet
should not be deserialized as a ValueSet
, but as a map.
from tracing.
Related Issues (20)
- Broken link on docs.rs HOT 3
- non_blocking writer do not work HOT 4
- Make method env_var_name public HOT 1
- Broken link in documentation. HOT 2
- [tracing_subscriber::filter::Builder] Proposal for supporting multiple default directives / setting a default filter
- Unqualified `line!` macro usage inside `info!` causes issues with `ratatui_macros` HOT 1
- How to modify EnvFilter instead of replace HOT 3
- RollingFileAppender `prune_old_logs()` relies on `metadata().created()` which is not available on all platforms HOT 1
- Make Layer::with_writer not truncate the file HOT 4
- When will the feature(`valuable` suport`) be merged into stable version? HOT 1
- error[E0609]: no field `free` on type `REGISTRY` HOT 3
- Add an option for outputting span IDs HOT 1
- RollingFileAppender: prefix and suffix custom separator
- `#instrument` attribute not making new spans HOT 2
- Execute custom code every time `error!` (etc) is called HOT 4
- Make path clickable HOT 2
- Lacking documentation of context propagation through channels HOT 2
- `fn subscriber` did exist in the main branch, but not in `tracing-subscriber-0.3.18` HOT 2
- Valuable: Enum Representations
- JSON: Field names should account for `r#` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tracing.