Function tracing_capture::predicates::field
source · pub fn field<P: IntoFieldPredicate>(
name: &'static str,
matches: P,
) -> FieldPredicate<P::Predicate>
Expand description
Creates a predicate for a particular field of a CapturedSpan
or CapturedEvent
.
§Arguments
The argument of this function is essentially a predicate for the TracedValue
of the field.
It may be:
bool
,i64
,i128
,u64
,u128
,f64
,&str
: will be compared to theTracedValue
using the correspondingPartialEq
implementation.- A predicate produced by the
value()
function. - Any
Predicate
forTracedValue
. To bypass Rust orphaning rules, the predicate must be enclosed in square brackets (i.e., a one-value array).
§Examples
let storage = SharedStorage::default();
let subscriber = Registry::default().with(CaptureLayer::new(&storage));
tracing::subscriber::with_default(subscriber, || {
tracing::info_span!("compute", arg = 5_i32).in_scope(|| {
tracing::info!("done");
});
});
let storage = storage.lock();
// All of these access the single captured span.
let spans = storage.scan_spans();
let _ = spans.single(&field("arg", [always()]));
let _ = spans.single(&field("arg", 5_i64));
let _ = spans.single(&field("arg", value(gt(3_i64))));