Skip to content
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

Use macros for module declarations on registry #1074

Merged
merged 3 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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