Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing log lines following query execution when using tracing_subscriber::Registry #3751

Open
zachcauchiatmerqury opened this issue Feb 19, 2025 · 0 comments
Labels

Comments

@zachcauchiatmerqury
Copy link

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 one fmt layer configured with an EnvFilter set to WARN,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) or WARN,sqlx::query=DEBUG,my_crate=DEBUG, the next log line after a query has been executed is logged as expected. If sqlx::query is set to INFO 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

  1. Set up a Postgres database on localhost:5432 with the following:
    • Username: example, Password: example
    • Database: example
    • One empty table named errtest.
  2. 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"] }
  1. 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`.");
  1. Run the code using cargo run.
  2. 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant