Function tracing_capture::predicates::target
source · pub fn target<P: IntoTargetPredicate>(
matches: P,
) -> TargetPredicate<P::Predicate>
Expand description
Creates a predicate for the target of a CapturedSpan
or CapturedEvent
.
§Arguments
The argument of this function may be:
&str
: will be compared as per standard target filtering. E.g.,target("tracing")
will matchtracing
andtracing::predicate
targets, but nottracing_capture
.- Any
str
Predicate
. 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!(target: "capture::test", "compute").in_scope(|| {
tracing::info!(answer = 42, "done");
});
});
let storage = storage.lock();
// All of these access the single captured span.
let spans = storage.scan_spans();
let _ = spans.single(&target("capture"));
let _ = spans.single(&target([starts_with("cap")]));