-
Notifications
You must be signed in to change notification settings - Fork 731
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
tracing, core: re-implement empty fields #548
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -635,7 +635,43 @@ impl Span { | |
self.field(field).is_some() | ||
} | ||
|
||
/// Visits that the field described by `field` has the value `value`. | ||
/// Records that the field described by `field` has the value `value`. | ||
/// | ||
/// This may be used with [`field::Empty`] to declare fields whose values | ||
/// are not known when the span is created, and record them later: | ||
/// ``` | ||
/// use tracing::{trace_span, field}; | ||
/// | ||
/// // Create a span with two fields: `greeting`, with the value "hello world", and | ||
/// // `parting`, without a value. | ||
/// let span = trace_span!("my_span", greeting = "hello world", parting = field::Empty); | ||
/// | ||
/// // ... | ||
/// | ||
/// // Now, record a value for parting as well. | ||
/// span.record("parting", &"goodbye world!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since "parting" needs to referenced as a string, I'd add a comment noting that difference between macros and normal function parameters as it took me a few seconds to parse the example in https://deploy-preview-548--tracing-rs.netlify.com/tracing/span/struct.span?search=#method.record. |
||
/// ``` | ||
/// However, it may also be used to record a _new_ value for a field whose | ||
/// value was already recorded: | ||
/// ``` | ||
/// use tracing::info_span; | ||
/// # fn do_something() -> Result<(), ()> { Err(()) } | ||
/// | ||
/// // Initially, let's assume that our attempt to do something is going okay... | ||
/// let span = info_span!("doing_something", is_okay = true); | ||
/// let _e = span.enter(); | ||
/// | ||
/// match do_something() { | ||
/// Ok(something) => { | ||
/// // ... | ||
/// } | ||
/// Err(_) => { | ||
/// // Things are no longer okay! | ||
/// span.record("is_okay", &false); | ||
/// } | ||
/// } | ||
/// ``` | ||
/// [`field::Empty`]: ../field/struct.Empty.html | ||
pub fn record<Q: ?Sized, V>(&self, field: &Q, value: &V) -> &Self | ||
where | ||
Q: field::AsField, | ||
|
@@ -654,7 +690,7 @@ impl Span { | |
self | ||
} | ||
|
||
/// Visit all the fields in the span | ||
/// Records all the fields in the provided `ValueSet`. | ||
pub fn record_all(&self, values: &field::ValueSet<'_>) -> &Self { | ||
let record = Record::new(values); | ||
if let Some(ref inner) = self.inner { | ||
|
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.
Same comment as I mentioned prior would be handy here too.