Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new filter methods #1973

Merged
merged 14 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 17 additions & 28 deletions tracing-subscriber/src/filter/layer_filters/combinator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! Filter combinators
use crate::layer::{Context, Filter};
use std::{cmp, fmt, marker::PhantomData};
use tracing_core::{subscriber::Interest, LevelFilter, Metadata};
use tracing_core::{
span::{Attributes, Id},
subscriber::Interest,
LevelFilter, Metadata,
};

/// Combines two [`Filter`]s so that spans and events are enabled if and only if
/// *both* filters return `true`.
Expand Down Expand Up @@ -134,30 +138,25 @@ where
}

#[inline]
fn on_new_span(
&self,
attrs: &tracing_core::span::Attributes<'_>,
id: &tracing_core::span::Id,
ctx: Context<'_, S>,
) {
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
self.a.on_new_span(attrs, id, ctx.clone());
tfreiberg-fastly marked this conversation as resolved.
Show resolved Hide resolved
self.b.on_new_span(attrs, id, ctx)
}

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

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

#[inline]
fn on_close(&self, id: tracing_core::span::Id, ctx: Context<'_, S>) {
fn on_close(&self, id: Id, ctx: Context<'_, S>) {
self.a.on_close(id.clone(), ctx.clone());
self.b.on_close(id, ctx);
}
Expand Down Expand Up @@ -319,30 +318,25 @@ where
Some(cmp::max(self.a.max_level_hint()?, self.b.max_level_hint()?))
}
#[inline]
hawkw marked this conversation as resolved.
Show resolved Hide resolved
fn on_new_span(
&self,
attrs: &tracing_core::span::Attributes<'_>,
id: &tracing_core::span::Id,
ctx: Context<'_, S>,
) {
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
self.a.on_new_span(attrs, id, ctx.clone());
tfreiberg-fastly marked this conversation as resolved.
Show resolved Hide resolved
self.b.on_new_span(attrs, id, ctx)
}

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

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

#[inline]
fn on_close(&self, id: tracing_core::span::Id, ctx: Context<'_, S>) {
fn on_close(&self, id: Id, ctx: Context<'_, S>) {
self.a.on_close(id.clone(), ctx.clone());
self.b.on_close(id, ctx);
}
Expand Down Expand Up @@ -415,27 +409,22 @@ where
}

#[inline]
fn on_new_span(
&self,
attrs: &tracing_core::span::Attributes<'_>,
id: &tracing_core::span::Id,
ctx: Context<'_, S>,
) {
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
self.a.on_new_span(attrs, id, ctx);
}

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

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

#[inline]
fn on_close(&self, id: tracing_core::span::Id, ctx: Context<'_, S>) {
fn on_close(&self, id: Id, ctx: Context<'_, S>) {
self.a.on_close(id, ctx);
}
}
Expand Down
12 changes: 9 additions & 3 deletions tracing-subscriber/src/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,19 +1069,25 @@ feature! {
///
/// By default, this method does nothing. `Filter` implementations that
/// need to be notified when a span is entered can override this method.
fn on_enter(&self, _id: &span::Id, _ctx: Context<'_, S>) {}
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
let _ = (id, ctx);
}

/// Notifies this filter that a span with the given ID was exited.
///
/// By default, this method does nothing. `Filter` implementations that
/// need to be notified when a span is exited can override this method.
fn on_exit(&self, _id: &span::Id, _ctx: Context<'_, S>) {}
fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
let _ = (id, ctx);
}

/// Notifies this filter that a span with the given ID has been closed.
///
/// By default, this method does nothing. `Filter` implementations that
/// need to be notified when a span is closed can override this method.
fn on_close(&self, _id: span::Id, _ctx: Context<'_, S>) {}
fn on_close(&self, id: span::Id, ctx: Context<'_, S>) {
let _ = (id, ctx);
}
}
}

Expand Down