Skip to content

Commit

Permalink
subscriber: add missing Filter::on_record for to EnvFilter (tokio…
Browse files Browse the repository at this point in the history
…-rs#2058)

Depends on tokio-rs#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 <eliza@buoyant.io>
  • Loading branch information
hawkw authored and kaffarell committed May 22, 2024
1 parent 5bf05cf commit fe27c15
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tracing-subscriber/src/filter/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,18 @@ impl EnvFilter {
}
}

/// Informs the filter that the span with the provided `id` recorded the
/// provided field `values`.
///
/// This is equivalent to calling the [`Layer::on_record`] or
/// [`Filter::on_record`] methods on `EnvFilter`'s implementations of those
/// traits, but it does not require the trait to be in scope
pub fn on_record<S>(&self, id: &span::Id, values: &span::Record<'_>, _: Context<'_, S>) {
if let Some(span) = try_lock!(self.by_id.read()).get(id) {
span.record_update(values);
}
}

fn cares_about_span(&self, span: &span::Id) -> bool {
let spans = try_lock!(self.by_id.read(), else return false);
spans.contains_key(span)
Expand Down

0 comments on commit fe27c15

Please sign in to comment.