Skip to content

Commit b0146c5

Browse files
committed
subscriber: add missing Filter::on_record for to EnvFilter (#2058)
Depends on #2057 ## Motivation Currently, `EnvFilter`'s `Layer` implementation provides a `Layer::on_record` method, but its `Filter` implementation is missing the corresponding `Filter::on_record` implementation. This means that when using `EnvFilter` as a per-layer filter, recording span fields after the spans were created will not update the filter state. ## Solution This commit factors out the `on_record` implementation for `Layer` into an inherent method, and adds a new `Filter::on_record` method that calls it as well. Signed-off-by: Eliza Weisman <[email protected]>
1 parent d554b2b commit b0146c5

File tree

1 file changed

+20
-4
lines changed
  • tracing-subscriber/src/filter/env

1 file changed

+20
-4
lines changed

tracing-subscriber/src/filter/env/mod.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,18 @@ impl EnvFilter {
588588
spans.remove(&id);
589589
}
590590

591+
/// Informs the filter that the span with the provided `id` recorded the
592+
/// provided field `values`.
593+
///
594+
/// This is equivalent to calling the [`Layer::on_record`] or
595+
/// [`Filter::on_record`] methods on `EnvFilter`'s implementations of those
596+
/// traits, but it does not require the trait to be in scope
597+
pub fn on_record<S>(&self, id: &span::Id, values: &span::Record<'_>, _: Context<'_, S>) {
598+
if let Some(span) = try_lock!(self.by_id.read()).get(id) {
599+
span.record_update(values);
600+
}
601+
}
602+
591603
fn cares_about_span(&self, span: &span::Id) -> bool {
592604
let spans = try_lock!(self.by_id.read(), else return false);
593605
spans.contains_key(span)
@@ -643,10 +655,9 @@ impl<S: Subscriber> Layer<S> for EnvFilter {
643655
self.on_new_span(attrs, id, ctx)
644656
}
645657

646-
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, _: Context<'_, S>) {
647-
if let Some(span) = try_lock!(self.by_id.read()).get(id) {
648-
span.record_update(values);
649-
}
658+
#[inline]
659+
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
660+
self.on_record(id, values, ctx);
650661
}
651662

652663
#[inline]
@@ -690,6 +701,11 @@ feature! {
690701
self.on_new_span(attrs, id, ctx)
691702
}
692703

704+
#[inline]
705+
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
706+
self.on_record(id, values, ctx);
707+
}
708+
693709
#[inline]
694710
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
695711
self.on_enter(id, ctx);

0 commit comments

Comments
 (0)