From 14eee0a167d949eda01e3790e7cbbe8ac3a72db0 Mon Sep 17 00:00:00 2001 From: Folyd Date: Fri, 16 Apr 2021 06:08:18 +0800 Subject: [PATCH] core: expose an accessor for the `FieldSet` on `Attributes` (#1331) ## 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 --- tracing-core/src/span.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tracing-core/src/span.rs b/tracing-core/src/span.rs index c793841de6..1d3ede1c63 100644 --- a/tracing-core/src/span.rs +++ b/tracing-core/src/span.rs @@ -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}; @@ -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 =====