Skip to content

Commit eb1dd70

Browse files
committed
Explain how various interest enablers work together
1 parent fde00c9 commit eb1dd70

File tree

1 file changed

+26
-1
lines changed
  • tracing-subscriber/src/subscribe

1 file changed

+26
-1
lines changed

tracing-subscriber/src/subscribe/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,31 @@ pub(crate) mod tests;
686686
/// be composed together with other subscribers to build a [collector]. See the
687687
/// [module-level documentation](crate::subscribe) for details.
688688
///
689+
/// # Enabling interest
690+
///
691+
/// Whenever an tracing event (or span) is emitted, it goes through a number of
692+
/// steps to determine how and how much it should be processed. The earlier an
693+
/// event is disabled, the less work has to be done to process the event, so
694+
/// subscribers should attempt to provide accurate information as early as
695+
/// possible. Note that this determines **global** interest for the entire stack
696+
/// of subscribers; a subscriber that wants to ignore certain events/spans
697+
/// should just ignore them in the notifications. In order, each event checks:
698+
///
699+
/// - [`register_callsite`], once per callsite (roughly: once per time that
700+
/// `event!` or `span!` is written in the source code; this is cached at the
701+
/// callsite). See [`Collect::register_callsite`] for how this behaves.
702+
/// - [`enabled`], once per emitted event (or span). This is the main point to
703+
/// (globally) filter events based on their [`Metadata`]. If an event can be
704+
/// disabled by just its structure, it should be, as this allows construction
705+
/// of the actual `Event`/`Span` to be skipped.
706+
/// - For events only (and not spans), [`event_enabled`] is called just before
707+
/// processing the event. This gives subscribers one last chance to say that
708+
/// an event should be filtered out, now that the event's fields are known.
709+
///
689710
/// [collector]: tracing_core::Collect
711+
/// [`enabled`]: Self::enabled
712+
/// [`event_enabled`]: Self::event_enabled
713+
/// [`register_callsite`]: Self::register_callsite
690714
#[cfg_attr(docsrs, doc(notable_trait))]
691715
pub trait Subscribe<C>
692716
where
@@ -827,7 +851,7 @@ where
827851
// seems like a good future-proofing measure as it may grow other methods later...
828852
fn on_follows_from(&self, _span: &span::Id, _follows: &span::Id, _ctx: Context<'_, C>) {}
829853

830-
/// Called before `on_event`, to determine if `on_event` should be called.
854+
/// Called before [`on_event`], to determine if `on_event` should be called.
831855
///
832856
/// <div class="example-wrap" style="display:inline-block">
833857
/// <pre class="ignore" style="white-space:normal;font:inherit;">
@@ -844,6 +868,7 @@ where
844868
/// See [the trait-level documentation] for more information on filtering
845869
/// with `Subscriber`s.
846870
///
871+
/// [`on_event`]: Self::on_event
847872
/// [`Interest`]: tracing_core::Interest
848873
/// [the trait-level documentation]: #filtering-with-subscribers
849874
#[inline] // collapse this to a constant please mrs optimizer

0 commit comments

Comments
 (0)