Skip to content

Commit

Permalink
chore: Use cfg_feature! for Module Declarations in Registry (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-nasa authored Nov 9, 2020
1 parent ef1d940 commit 710228e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 54 deletions.
18 changes: 8 additions & 10 deletions tracing-subscriber/src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,16 @@ use tracing_core::{field::FieldSet, span::Id, Metadata};

/// A module containing a type map of span extensions.
mod extensions;
#[cfg(feature = "registry")]
mod sharded;
#[cfg(feature = "registry")]
mod stack;

cfg_feature!("registry", {
mod sharded;
mod stack;

pub use sharded::Data;
pub use sharded::Registry;
});

pub use extensions::{Extensions, ExtensionsMut};
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub use sharded::Data;
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
pub use sharded::Registry;

/// Provides access to stored span data.
///
Expand Down
86 changes: 42 additions & 44 deletions tracing-subscriber/src/registry/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,49 @@ use tracing_core::{
Collect, Event, Interest, Metadata,
};

/// A shared, reusable store for spans.
///
/// A `Registry` is a [`Collect`] around which multiple subscribers
/// implementing various behaviors may be [added]. Unlike other types
/// implementing `Collect`, `Registry` does not actually record traces itself:
/// instead, it collects and stores span data that is exposed to any `Subscriber`s
/// wrapping it through implementations of the [`LookupSpan`] trait.
/// The `Registry` is responsible for storing span metadata, recording
/// relationships between spans, and tracking which spans are active and whicb
/// are closed. In addition, it provides a mechanism for `Subscriber`s to store
/// user-defined per-span data, called [extensions], in the registry. This
/// allows `Subscriber`-specific data to benefit from the `Registry`'s
/// high-performance concurrent storage.
///
/// This registry is implemented using a [lock-free sharded slab][slab], and is
/// highly optimized for concurrent access.
///
/// [slab]: https://docs.rs/crate/sharded-slab/
/// [`Subscriber`]: crate::Subscribe
/// [added]: crate::FmtSubscriber::with_collector()
/// [extensions]: super::Extensions
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
#[derive(Debug)]
pub struct Registry {
spans: Pool<DataInner>,
current_spans: ThreadLocal<RefCell<SpanStack>>,
}
cfg_feature!("registry", {
/// A shared, reusable store for spans.
///
/// A `Registry` is a [`Collect`] around which multiple subscribers
/// implementing various behaviors may be [added]. Unlike other types
/// implementing `Collect`, `Registry` does not actually record traces itself:
/// instead, it collects and stores span data that is exposed to any `Subscriber`s
/// wrapping it through implementations of the [`LookupSpan`] trait.
/// The `Registry` is responsible for storing span metadata, recording
/// relationships between spans, and tracking which spans are active and whicb
/// are closed. In addition, it provides a mechanism for `Subscriber`s to store
/// user-defined per-span data, called [extensions], in the registry. This
/// allows `Subscriber`-specific data to benefit from the `Registry`'s
/// high-performance concurrent storage.
///
/// This registry is implemented using a [lock-free sharded slab][slab], and is
/// highly optimized for concurrent access.
///
/// [slab]: https://docs.rs/crate/sharded-slab/
/// [`Subscriber`]: crate::Subscribe
/// [added]: crate::FmtSubscriber::with_collector()
/// [extensions]: super::Extensions
#[derive(Debug)]
pub struct Registry {
spans: Pool<DataInner>,
current_spans: ThreadLocal<RefCell<SpanStack>>,
}

/// Span data stored in a [`Registry`].
///
/// The registry stores well-known data defined by tracing: span relationships,
/// metadata and reference counts. Additional user-defined data provided by
/// [`Subscriber`s], such as formatted fields, metrics, or distributed traces should
/// be stored in the [extensions] typemap.
///
/// [`Subscriber`s]: crate::Subscribe
/// [extensions]: Extensions
#[cfg(feature = "registry")]
#[cfg_attr(docsrs, doc(cfg(feature = "registry")))]
#[derive(Debug)]
pub struct Data<'a> {
/// Immutable reference to the pooled `DataInner` entry.
inner: Ref<'a, DataInner>,
}
/// Span data stored in a [`Registry`].
///
/// The registry stores well-known data defined by tracing: span relationships,
/// metadata and reference counts. Additional user-defined data provided by
/// [`Subscriber`s], such as formatted fields, metrics, or distributed traces should
/// be stored in the [extensions] typemap.
///
/// [`Subscriber`s]: crate::Subscribe
/// [extensions]: Extensions
#[derive(Debug)]
pub struct Data<'a> {
/// Immutable reference to the pooled `DataInner` entry.
inner: Ref<'a, DataInner>,
}
});

/// Stored data associated with a span.
///
Expand Down

0 comments on commit 710228e

Please sign in to comment.