I'm able to emit events using https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.Layer.html#method.with_span_events, but they are created at TRACE level. Is there any way to cause these to be created at a different level?
control level of synthetic events from .with_span_events()?
118 Views Asked by ajp At
3
There are 3 best solutions below
0
On
From https://docs.rs/tracing/latest/tracing/attr.instrument.html:
Unless overridden, a span with the
INFOlevel will be generated...
So you can change the generated span events' level by setting level argument of #[instrument] macro.
#[instrument(level = "debug")]
pub fn my_function() {
}
0
On
The level is determined by the span's itself level, and this is hardcoded and cannot be changed.
The level of the span can be set:
If you are using the
span!()macro, the first argument is the level. Or you can use one of the shortcut macros:trace_span!()etc..If you are using
#[instrument], you can pass alevel = "<level>"argument to it.
You can create events using the event! macro with the desired level specified, e.g.
Or even better you can use the shorthand macros for each level