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 15, 2021
1 parent 9b1e113 commit 03e9ee4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tracing-core/src/span.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! 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::{field, Metadata};
use core::num::NonZeroU64;

/// Identifies a span within the context of a collector.
///
Expand Down Expand Up @@ -195,6 +197,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 03e9ee4

Please sign in to comment.