Open
Description
I have found these related issues/pull requests
Cannot find any related issues on the sqlx
repo. When looking at the tracing
repo, this issue is related to the observed bug. I'm not sure if this qualifies as a tracing
bug or an sqlx
bug so apologies in advance if it's the former.
Description
- When using a
tracing_subscriber::Registry
as the global subscriber, with onefmt
layer configured with anEnvFilter
set toWARN,my_crate=DEBUG
, the next log line after a query has been executed is not logged. - When that layer filter is EITHER configured as
INFO
(any log level works) orWARN,sqlx::query=DEBUG,my_crate=DEBUG
, the next log line after a query has been executed is logged as expected. Ifsqlx::query
is set toINFO
level or higher, the log line is not logged. - If multiple layers are configured in the registry, but at least one meets the above filter requirements, then the log line is logged as expected.
- When using a
tracing_subscriber::fmt()
subscriber as the global, even when the above filter conditions aren't met, the log line is logged as expected.
Reproduction steps
- Set up a Postgres database on
localhost:5432
with the following:- Username:
example
, Password:example
- Database:
example
- One empty table named
errtest
.
- Username:
- Set up a
bin
crate with the following dependencies:
sqlx = { version = "=0.8.3", features = ["postgres", "runtime-tokio"] }
tracing = "=0.1.41"
tracing-subscriber = { version = "=0.3.19", features = ["env-filter"] }
tracing-appender = "=0.2.3"
tokio = { version = "1.43.0", features = ["full"] }
- Paste in the following code into the
main.rs::main
function:
let console_filter = EnvFilter::try_new("INFO,my_crateDEBUG")?;
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().with_filter(console_filter))
.init();
let pool = sqlx::PgPool::connect("postgres://example:example@localhost:5432/example").await?;
info!("0. Logging before a query.");
let _ = sqlx::query!("SELECT * FROM errtest;")
.fetch_all(&pool)
.await?;
debug!("1. This doesn't get printed without `sqlx::query=DEBUG`.");
debug!("2. This does get printed even without `sqlx::query=DEBUG`.");
- Run the code using
cargo run
. - The following should be printed in the terminal:
Compiling my_crate v0.1.0 (/home/zachc/Repositories/my_crate)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.50s
Running `target/debug/my_crate`
2025-02-19T07:43:43.673942Z INFO my_crate: 0. Logging before a query.
2025-02-19T07:43:43.676540Z DEBUG my_crate: 2. This does get printed even without `sqlx::query=DEBUG`.
SQLx version
0.8.3
Enabled SQLx features
postgres, runtime-tokio
Database server and version
Postgres
Operating system
Windows (running WSL2)
Rust version
rustc 1.84.1 (e71f9a9a9 2025-01-27)