-
See this test app: use tracing::instrument;
use tracing_subscriber::{prelude::*, EnvFilter};
fn main() {
let env_filter = EnvFilter::try_from_env("TEST").unwrap();
let (non_blocking, _non_block_guard) = tracing_appender::non_blocking(std::io::stdout());
let mut fmt_layer = tracing_subscriber::fmt::layer()
.with_thread_ids(true)
.with_target(true)
.with_writer(non_blocking);
fmt_layer = fmt_layer.with_span_events(
tracing_subscriber::fmt::format::FmtSpan::ENTER
| tracing_subscriber::fmt::format::FmtSpan::CLOSE,
);
let subscriber = tracing_subscriber::Registry::default()
.with(env_filter)
.with(fmt_layer);
tracing::subscriber::set_global_default(subscriber).expect("Failed to set subscriber");
test();
}
#[instrument(name = "function span", level = "debug", fields(badger = "mushroom"))]
fn test() {
tracing::debug!("debug");
tracing::info!("info");
} When running with
But with
That's because the span is Is there any way to do that? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
hawkw
Jan 9, 2024
Replies: 1 comment 3 replies
-
If you disable the |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
hawkw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you disable the
DEBUG
level with filtering, then spans at theDEBUG
level will not be recorded. If you want your span to be recorded whenDEBUG
is disabled, consider changing the level of your span toINFO
or higher.