-
Notifications
You must be signed in to change notification settings - Fork 707
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
fmt layer is append-only causing to to grow forever while Span::record replaces values #2334
Comments
I suspect that the suggested thing to do is something like Still, unsure if this shouldn't just be the default behaviour of original layer. |
OK, I did some digging and tried to mimic the JSON implementation. I've come to realise that building on top of So I guess this means a real solution will implement a new layer instead and use whatever state it requires in |
I have today discovered that |
Yes, this is intended behavior. Unfortunately, rewriting values requires maintaining state to index, mutate and reformat the log entry. A better way would be to make your own |
OK. I guess we can close the ticket? I suppose json formatter should be own layer to performance reasons and tracing-journald should also be updated to only emit one field but we can open separate tickets for those if needed... |
I've just run into this - and the built-in JSON (or compact, or full, whatever) formatter would be great to be able to use in situations like these. They look nice, they're flexible, they work well. Having to go implement your own layer just to avoid this duplication is a pretty big lift for something that seems like it ought to work by default. So just throwing my 2c out there to keep this open and hopefully get a fix in for it |
* Spans now generated for every packet and timeout event * Ephemeral "startup" span runs before main loop kicks off * `self.state` and `self.term` logged on parent spans; removed from individual event fields n.b. There is a bug in tracing_subscriber that causes the term field to be logged twice when an election timeout occurs in Candidate state. The `tracing` crate correctly updates the original `term` field on the span to the new value, but `tracing_subscriber` only appends new values to the log line for... reasons. See: tokio-rs/tracing#2334
I'm going to close this issue in favor of #2123 in order to make things a little more managable. |
Bug Report
Version
Platform
Linux aya 5.15.67 #1-NixOS SMP Thu Sep 8 10:32:54 UTC 2022 x86_64 GNU/Linux
Crates
tracing-subscriber
Description
We have some code where we have a long-running
tracing::Span
with a bunch of fields. Over the course of its life, we update the values of those fields: this seems to be explicitly allowed and documented.However, we also use the
tracing_subscriber::fmt::Layer
in the same program and every time werecord
a replacement of a field in theSpan
, the new value is appended to the formatted fields instead of replaced as we were expecting. This is unexpected: I don't care to see old values, I'm trying to explicitly replace them. I proved small code sample below that hopefully makes it obvious what I mean:I would like to only see a single
loop_ix
in the output but I see each one.I have chased down the code inside tracing and I think I understand roughly what happens on
Span::record
. The default fmt layer is backed byDefaultFields
and stores the formatted data insideFormattedFields<DefaultFields>
which is just someString
storage. On recording a value, it ends up callingadd_fields
with the storage from inside the span which just adds an space to the back then invokesformat_fields
.format_fields
makesDefaultVisitor
and invokes arecord
method on that which eventually goes through variousrecord_*
methods and ends up inrecord_debug
.record_debug
then actually handles the formatting of the value and appends it to the writer, which is the original mutableString
.It does not track what fields it has already formatted – fine. But in that case it seems like it's incompatible outside the box with replacing values in spans.
Is this expected behaviour? I suspect yes: in which case, what's the right thing to do here?
The text was updated successfully, but these errors were encountered: