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
feat: add a tracing span for queries #3176
base: main
Are you sure you want to change the base?
Conversation
I also was starting to play around with something like this, but this breaks you try to use it because I'm not that deep in async specifics yet, the alternative would be to try to instrument the future itself, which would be only tricky depending if you want to include both executing the query & fetching the results in the time. |
Hmm, how does it break? I tried to use my code and it seemed to work and produce reasonable-looking spans but admittedly it was a pretty simple setup. |
Interesting 😄 I'll recheck with your PR |
Yep, happens with your code too (I can't rule out I made a mistake somehow): Error is:
test code is just the sqlx example: use sqlx::postgres::PgPoolOptions;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let pool = PgPoolOptions::new()
.max_connections(5)
.connect("postgres://localhost/test")
.await?;
let row: (i64,) = sqlx::query_as("SELECT $1")
.bind(150_i64)
.fetch_one(&pool)
.await?;
assert_eq!(row.0, 150);
Ok(())
} |
( using sqlx as a path dependency) |
I see - I had only tried this with the SQLite driver which does not use |
This is a sketch of adding a tracing span for SQL queries. There is already a tracing event with the right information in
QueryLogger
- I decided to leave it as is and duplicate the row counts in the span. In theory, you would not need the event when the span is there, but in practice not everyone's logging setup will show the spans so keeping it is the safest choice.log
to tracing #2177.