-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add option to emit fields as text associated with span #87
Conversation
Conversely, it is commonplace in Even in your case I would possibly see That said, I don’t disagree that in some applications the suggested rendition might be preferable, but I suspect it will need to be a setting/option to land, rather than an unconditional change as proposed. |
Great points, you're absolutely right that the current behavior is still desirable. I went ahead and added a flag at the Layer level. This is somewhat unfortunate in that you can't decide per span whether or not you want combining, but having a layer level default is still useful and so if we do figure out how to do per span flags that feature will be in addition to this one. |
tracing-tracy/src/lib.rs
Outdated
if let Some(fields) = self | ||
.fields_in_zone_name | ||
.then_some(fields) | ||
.flatten() | ||
.filter(|f| !f.fields.is_empty()) | ||
{ | ||
CACHE.with(|cache| { | ||
let mut buf = cache.acquire(); | ||
let _ = write!(buf, "{}{{{}}}", metadata.name(), fields.fields); | ||
span(&buf) | ||
}) | ||
} else { | ||
span(metadata.name()) | ||
} | ||
}; | ||
if let Some(fields) = (!self.fields_in_zone_name).then_some(fields).flatten() { | ||
stack_frame.0.emit_text(self.truncate_to_length( | ||
(u16::MAX - 1).into(), | ||
&fields.fields, | ||
"span field values are too long and were truncated", | ||
)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW then_some(()).and(fields)
might have been nicer and avoids constructing doubly-nested option.
Alternatively, you could write
if let Some(fields) = self | |
.fields_in_zone_name | |
.then_some(fields) | |
.flatten() | |
.filter(|f| !f.fields.is_empty()) | |
{ | |
CACHE.with(|cache| { | |
let mut buf = cache.acquire(); | |
let _ = write!(buf, "{}{{{}}}", metadata.name(), fields.fields); | |
span(&buf) | |
}) | |
} else { | |
span(metadata.name()) | |
} | |
}; | |
if let Some(fields) = (!self.fields_in_zone_name).then_some(fields).flatten() { | |
stack_frame.0.emit_text(self.truncate_to_length( | |
(u16::MAX - 1).into(), | |
&fields.fields, | |
"span field values are too long and were truncated", | |
)); | |
} | |
match fields { | |
None => span(metadata.name()), | |
// NOTE: the current proposed code will `emit_text` even for empty fields! | |
Some(fields) if fields.is_empty() => span(metadata.name()), | |
Some(fields) if self.fields_in_zone_name => { | |
CACHE.with(|cache| { | |
let mut buf = cache.acquire(); | |
let _ = write!(buf, "{}{{{}}}", metadata.name(), fields.fields); | |
span(&buf) | |
}) | |
} | |
Some(fields) => { | |
let span = span(metadata.name()); | |
span.emit_text(...); | |
span | |
} | |
} |
which seems a more straightforward read, isn’t it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's quite a bit clearer, thanks! And great catch on the empty fields bug. :)
…an name Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Depends on #86.
This is desirable because otherwise you cannot get meaningful statistics when tracing functions:
will turn into separate zones which can't be analyzed as a whole:
After this change, you get nice clean zones:
And the debug data is still present:
Of course as a bonus we save an allocation and formatting time.