Skip to content

Commit e065edb

Browse files
CAD97hawkw
andcommitted
Apply code review documentation improvements
Co-authored-by: Eliza Weisman <[email protected]>
1 parent 53ed1dc commit e065edb

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

tracing-core/src/collect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ use core::ptr::NonNull;
5757
/// See also the [documentation on the callsite registry][cs-reg] for details
5858
/// on [`register_callsite`].
5959
///
60-
/// - [`event_enabled`] is called once before every [`event`] is recorded. This
61-
/// can be used to implement filtering on events once their field values are
62-
/// known but before any processing is done in `event`.
60+
/// - [`event_enabled`] is called once before every call to the [`event`]
61+
/// method. This can be used to implement filtering on events once their field
62+
/// values are known, but before any processing is done in the `event` method.
6363
/// - [`clone_span`] is called every time a span ID is cloned, and [`try_close`]
6464
/// is called when a span ID is dropped. By default, these functions do
6565
/// nothing. However, they can be used to implement reference counting for

tracing-subscriber/src/subscribe/mod.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,28 @@
417417
//! [`Interest::never()`] from its [`register_callsite`] method, filter
418418
//! evaluation will short-circuit and the span or event will be disabled.
419419
//!
420+
//! ### Enabling interest
421+
//!
422+
//! Whenever an tracing event (or span) is emitted, it goes through a number of
423+
//! steps to determine how and how much it should be processed. The earlier an
424+
//! event is disabled, the less work has to be done to process the event, so
425+
//! subscribers that implement filtering should attempt to disable unwanted
426+
//! events as early as possible. In order, each event checks:
427+
//!
428+
//! - [`register_callsite`], once per callsite (roughly: once per time that
429+
//! `event!` or `span!` is written in the source code; this is cached at the
430+
//! callsite). See [`Collect::register_callsite`] and
431+
//! [`tracing_core::callsite`] for a summary of how this behaves.
432+
//! - [`enabled`], once per emitted event (roughly: once per time that `event!`
433+
//! or `span!` is *executed*), and only if `register_callsite` regesters an
434+
//! [`Interest::sometimes`]. This is the main customization point to globally
435+
//! filter events based on their [`Metadata`]. If an event can be disabled
436+
//! based only on [`Metadata`], it should be, as this allows the construction
437+
//! of the actual `Event`/`Span` to be skipped.
438+
//! - For events only (and not spans), [`event_enabled`] is called just before
439+
//! processing the event. This gives subscribers one last chance to say that
440+
//! an event should be filtered out, now that the event's fields are known.
441+
//!
420442
//! ## Per-Subscriber Filtering
421443
//!
422444
//! **Note**: per-subscriber filtering APIs currently require the [`"registry"` crate
@@ -639,6 +661,7 @@
639661
//! [the current span]: Context::current_span
640662
//! [`register_callsite`]: Subscribe::register_callsite
641663
//! [`enabled`]: Subscribe::enabled
664+
//! [`event_enabled`]: Subscribe::event_enabled
642665
//! [`on_enter`]: Subscribe::on_enter
643666
//! [`Subscribe::register_callsite`]: Subscribe::register_callsite
644667
//! [`Subscribe::enabled`]: Subscribe::enabled
@@ -858,10 +881,10 @@ where
858881
///
859882
/// **Note**: This method determines whether an event is globally enabled,
860883
/// *not* whether the individual subscriber will be notified about the
861-
/// event. This is intended to be used by layers that implement filtering
862-
/// for the entire stack. Layers which do not wish to be notified about
863-
/// certain events but do not wish to globally disable them should ignore
864-
/// those events in their [on_event][Self::on_event].
884+
/// event. This is intended to be used by subscibers that implement
885+
/// filtering for the entire stack. Subscribers which do not wish to be
886+
/// notified about certain events but do not wish to globally disable them
887+
/// should ignore those events in their [on_event][Self::on_event].
865888
///
866889
/// </pre></div>
867890
///

0 commit comments

Comments
 (0)