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)
- make local time not need unsound feature HOT 1
- macros.rs ::core conflicts HOT 2
- Unexpected side-effect in Dispatch::new HOT 1
- tracing-appender: Build error with rust-nightly: type annotations needed for Box<_> HOT 2
- All log/tracing-log outputs have 4 spaces on the end HOT 1
- `Name / parent` form of `event!()` macro doesn't compile
- Integration With Anyhow HOT 1
- Conditional logs HOT 2
- Add `once` and per-level tracing macros that are called only once
- Cannot write custom `Layer` that uses `Format` HOT 2
- Attribute for logging every line in the function HOT 2
- Leveled logging is ignoring RUST_LOG HOT 4
- `SubscriberBuilder::with_ansi` is incorrectly gated by the `ansi` feature in tracing-subscriber 0.3.18 HOT 1
- A Spans `on_close` method is called with 45 minutes delay HOT 3
- tracing-appender: log rotation doesn't work with musl target HOT 3
- Allow macro `instrument` to accept multiple `fields` and `skip` and merge them
- 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
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.