Skip to content

Commit

Permalink
core: expose an accessor for the FieldSet on Attributes (#1331)
Browse files Browse the repository at this point in the history
## Motivation

Exposing an accessor for the `FieldSet` on `Attributes` can motivate the
subscriber to achieve some performance improvement, such as
`OpenTelemetrySubscriber` #1327.

## Alternative

Make `ValueSet::field_set()` be `pub` instead of `pub(crate)`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
Folyd and hawkw committed Apr 16, 2021
1 parent 3b52afc commit d45b6c5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tracing-core/src/span.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! Spans represent periods of time in the execution of a program.
use core::num::NonZeroU64;

use crate::field::FieldSet;
use crate::parent::Parent;
use crate::stdlib::num::NonZeroU64;
use crate::{field, Metadata};
Expand Down Expand Up @@ -196,6 +199,21 @@ impl<'a> Attributes<'a> {
pub fn is_empty(&self) -> bool {
self.values.is_empty()
}

/// Returns the set of all [fields] defined by this span's [`Metadata`].
///
/// Note that the [`FieldSet`] returned by this method includes *all* the
/// fields declared by this span, not just those with values that are recorded
/// as part of this set of `Attributes`. Other fields with values not present in
/// this `Attributes`' value set may [record] values later.
///
/// [fields]: crate::field
/// [record]: Attributes::record()
/// [`Metadata`]: crate::metadata::Metadata
/// [`FieldSet`]: crate::field::FieldSet
pub fn fields(&self) -> &FieldSet {
self.values.field_set()
}
}

// ===== impl Record =====
Expand Down

0 comments on commit d45b6c5

Please sign in to comment.