@@ -301,9 +301,55 @@ pub trait FilterExt<S>: subscribe::Filter<S> {
301
301
///
302
302
/// This inverts the values returned by the [`enabled`] and [`callsite_enabled`]
303
303
/// methods on the wrapped filter; it does *not* invert [`event_enabled`], as
304
- /// implementing that method is optional, and filters which do not implement
305
- /// filtering on event field values will return `true` even for events that their
306
- /// [`enabled`] method would disable.
304
+ /// filters which do not implement filtering on event field values will return
305
+ /// the default `true` even for events that their [`enabled`] method disables.
306
+ ///
307
+ /// Consider a normal filter defined as:
308
+ ///
309
+ /// ```ignore (pseudo-code)
310
+ /// // for spans
311
+ /// match callsite_enabled() {
312
+ /// ALWAYS => on_span(),
313
+ /// SOMETIMES => if enabled() { on_span() },
314
+ /// NEVER => (),
315
+ /// }
316
+ /// // for events
317
+ /// match callsite_enabled() {
318
+ /// ALWAYS => on_event(),
319
+ /// SOMETIMES => if enabled() && event_enabled() { on_event() },
320
+ /// NEVER => (),
321
+ /// }
322
+ /// ```
323
+ ///
324
+ /// and an inverted filter defined as:
325
+ ///
326
+ /// ```ignore (pseudo-code)
327
+ /// // for spans
328
+ /// match callsite_enabled() {
329
+ /// ALWAYS => (),
330
+ /// SOMETIMES => if !enabled() { on_span() },
331
+ /// NEVER => on_span(),
332
+ /// }
333
+ /// // for events
334
+ /// match callsite_enabled() {
335
+ /// ALWAYS => (),
336
+ /// SOMETIMES => if !enabled() { on_event() },
337
+ /// NEVER => on_event(),
338
+ /// }
339
+ /// ```
340
+ ///
341
+ /// A proper inversion would do `!(enabled() && event_enabled())` (or
342
+ /// `!enabled() || !event_enabled()`), but because of the implicit `&&`
343
+ /// relation between `enabled` and `event_enabled`, it is difficult to
344
+ /// short circuit and not call the wrapped `event_enabled`.
345
+ ///
346
+ /// A combinator which remembers the result of `enabled` in order to call
347
+ /// `event_enabled` only when `enabled() == true` is possible, but requires
348
+ /// additional thread-local mutable state to support a very niche use case.
349
+ //
350
+ // Also, it'd mean the wrapped layer's `enabled()` always gets called and
351
+ // globally applied to events where it doesn't today, since we can't know
352
+ // what `event_enabled` will say until we have the event to call it with.
307
353
///
308
354
/// [`Filter`]: crate::subscribe::Filter
309
355
/// [`enabled`]: crate::subscribe::Filter::enabled
0 commit comments