Skip to content

Commit

Permalink
subscriber: add missing Filter::on_record for to EnvFilter (#2058)
Browse files Browse the repository at this point in the history
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 <eliza@buoyant.io>
  • Loading branch information
hawkw committed Apr 9, 2022
1 parent d554b2b commit b0146c5
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tracing-subscriber/src/filter/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,18 @@ impl EnvFilter {
spans.remove(&id);
}

/// 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 Expand Up @@ -643,10 +655,9 @@ impl<S: Subscriber> Layer<S> for EnvFilter {
self.on_new_span(attrs, id, ctx)
}

fn on_record(&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);
}
#[inline]
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
self.on_record(id, values, ctx);
}

#[inline]
Expand Down Expand Up @@ -690,6 +701,11 @@ feature! {
self.on_new_span(attrs, id, ctx)
}

#[inline]
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
self.on_record(id, values, ctx);
}

#[inline]
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
self.on_enter(id, ctx);
Expand Down

0 comments on commit b0146c5

Please sign in to comment.