Skip to content

Commit

Permalink
core: document the callsite module (tokio-rs#2088)
Browse files Browse the repository at this point in the history
Currently, there isn't a lot of documentation explaining what callsites
and registration are for, and how they work. There's some documentation
explaining this stuff, but it's all on the `register_callsite` *method*,
rather than in the `callsite` module itself. We should fix that.

This branch adds new documentation to `tracing-core`'s `callsite`
module. Hopefully this should shine some light on how this part of
tracing works.

Thanks to @JamesHallowell for fixing some typos!

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw authored and kaffarell committed May 22, 2024
1 parent c5fa327 commit 5c7abbb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tracing-core/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ use crate::stdlib::{
/// Additionally, subscribers which wish to perform a behaviour once for each
/// callsite, such as allocating storage for data related to that callsite,
/// can perform it in `register_callsite`.
///
/// See also the [documentation on the callsite registry][cs-reg] for details
/// on [`register_callsite`].
///
/// - [`clone_span`] is called every time a span ID is cloned, and [`try_close`]
/// is called when a span ID is dropped. By default, these functions do
/// nothing. However, they can be used to implement reference counting for
Expand All @@ -70,10 +74,11 @@ use crate::stdlib::{
/// [`enabled`]: Subscriber::enabled
/// [`clone_span`]: Subscriber::clone_span
/// [`try_close`]: Subscriber::try_close
/// [cs-reg]: crate::callsite#registering-callsites
pub trait Subscriber: 'static {
// === Span registry methods ==============================================

/// Registers a new callsite with this subscriber, returning whether or not
/// Registers a new [callsite] with this subscriber, returning whether or not
/// the subscriber is interested in being notified about the callsite.
///
/// By default, this function assumes that the subscriber's [filter]
Expand Down Expand Up @@ -127,6 +132,9 @@ pub trait Subscriber: 'static {
/// return `Interest::Never`, as a new subscriber may be added that _is_
/// interested.
///
/// See the [documentation on the callsite registry][cs-reg] for more
/// details on how and when the `register_callsite` method is called.
///
/// # Notes
/// This function may be called again when a new subscriber is created or
/// when the registry is invalidated.
Expand All @@ -135,10 +143,12 @@ pub trait Subscriber: 'static {
/// _may_ still see spans and events originating from that callsite, if
/// another subscriber expressed interest in it.
///
/// [filter]: Subscriber::enabled()
/// [callsite]: crate::callsite
/// [filter]: Self::enabled
/// [metadata]: super::metadata::Metadata
/// [`enabled`]: Subscriber::enabled()
/// [`rebuild_interest_cache`]: super::callsite::rebuild_interest_cache
/// [cs-reg]: crate::callsite#registering-callsites
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
if self.enabled(metadata) {
Interest::always()
Expand Down

0 comments on commit 5c7abbb

Please sign in to comment.