Skip to content

Commit

Permalink
subscriber: add Filter::on_record callback
Browse files Browse the repository at this point in the history
Currently, `Filter` only has the `on_new_span`, `on_enter`, `on_exit`,
and `on_close` callbacks. This means it won't handle cases where a
span records a new field value that changes its filter state.

This branch adds the missing `on_record` callback.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Mar 29, 2022
1 parent 70fcfce commit 7e4724d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
19 changes: 18 additions & 1 deletion tracing-subscriber/src/filter/subscriber_filters/combinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::subscribe::{Context, Filter};
use std::{cmp, fmt, marker::PhantomData};
use tracing_core::{
collect::Interest,
span::{Attributes, Id},
span::{Attributes, Id, Record},
LevelFilter, Metadata,
};

Expand Down Expand Up @@ -143,6 +143,12 @@ where
self.b.on_new_span(attrs, id, ctx)
}

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

#[inline]
fn on_enter(&self, id: &Id, ctx: Context<'_, S>) {
self.a.on_enter(id, ctx.clone());
Expand Down Expand Up @@ -324,6 +330,12 @@ where
self.b.on_new_span(attrs, id, ctx)
}

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

#[inline]
fn on_enter(&self, id: &Id, ctx: Context<'_, S>) {
self.a.on_enter(id, ctx.clone());
Expand Down Expand Up @@ -414,6 +426,11 @@ where
self.a.on_new_span(attrs, id, ctx);
}

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

#[inline]
fn on_enter(&self, id: &Id, ctx: Context<'_, S>) {
self.a.on_enter(id, ctx);
Expand Down
3 changes: 2 additions & 1 deletion tracing-subscriber/src/filter/subscriber_filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ where

fn on_record(&self, span: &span::Id, values: &span::Record<'_>, cx: Context<'_, C>) {
if let Some(cx) = cx.if_enabled_for(span, self.id()) {
self.subscriber.on_record(span, values, cx)
self.filter.on_record(span, values, cx.clone());
self.subscriber.on_record(span, values, cx);
}
}

Expand Down
10 changes: 10 additions & 0 deletions tracing-subscriber/src/subscribe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,16 @@ pub trait Filter<S> {
let _ = (attrs, id, ctx);
}

/// Notifies this filter that a span with the given `Id` recorded the given
/// `values`.
///
/// By default, this method does nothing. `Filter` implementations that
/// need to be notified when new spans are created can override this
/// method.
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
let _ = (id, values, ctx);
}

/// Notifies this filter that a span with the given ID was entered.
///
/// By default, this method does nothing. `Filter` implementations that
Expand Down

0 comments on commit 7e4724d

Please sign in to comment.