Skip to content
Snippets Groups Projects
Commit 15184d1a authored by Jason Volk's avatar Jason Volk
Browse files

Add span scope names array to capture filter data; optimize values visitor vec.


Signed-off-by: default avatarJason Volk <jason@zemos.net>
parent 0c6bbde2
No related branches found
No related tags found
1 merge request!545Admin command tracing capture
......@@ -7,7 +7,8 @@ pub struct Data<'a> {
pub layer: &'a Layer,
pub event: &'a Event<'a>,
pub current: &'a Current,
pub values: Option<&'a mut [Value]>,
pub values: &'a [Value],
pub scope: &'a [&'static str],
}
impl Data<'_> {
......@@ -23,8 +24,6 @@ pub fn span_name(&self) -> &str { self.current.metadata().map_or("", |s| s.name(
#[must_use]
pub fn message(&self) -> &str {
self.values
.as_ref()
.expect("values are not composed for a filter")
.iter()
.find(|(k, _)| *k == "message")
.map_or("", |(_, v)| v.as_str())
......
use std::{fmt, sync::Arc};
use arrayvec::ArrayVec;
use tracing::field::{Field, Visit};
use tracing_core::{Event, Subscriber};
use tracing_subscriber::{layer::Context, registry::LookupSpan};
use super::{Capture, Data, State};
pub type Value = (&'static str, String);
pub struct Layer {
state: Arc<State>,
}
struct Visitor {
values: Vec<Value>,
values: Values,
}
type Values = ArrayVec<Value, 32>;
pub type Value = (&'static str, String);
type ScopeNames = ArrayVec<&'static str, 32>;
impl Layer {
#[inline]
pub fn new(state: &Arc<State>) -> Self {
......@@ -51,8 +55,9 @@ fn handle<S>(layer: &Layer, capture: &Capture, event: &Event<'_>, ctx: &Context<
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let names = ScopeNames::new();
let mut visitor = Visitor {
values: Vec::new(),
values: Values::new(),
};
event.record(&mut visitor);
......@@ -61,7 +66,8 @@ fn handle<S>(layer: &Layer, capture: &Capture, event: &Event<'_>, ctx: &Context<
layer,
event,
current: &ctx.current_span(),
values: Some(&mut visitor.values),
values: &visitor.values,
scope: &names,
});
}
......@@ -69,12 +75,21 @@ fn filter<S>(layer: &Layer, capture: &Capture, event: &Event<'_>, ctx: &Context<
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let values = Values::new();
let mut names = ScopeNames::new();
if let Some(scope) = ctx.event_scope(event) {
for span in scope {
names.push(span.name());
}
}
capture.filter.as_ref().map_or(true, |filter| {
filter(Data {
layer,
event,
current: &ctx.current_span(),
values: None,
values: &values,
scope: &names,
})
})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment