Fix user tracing of DO SQL queries and add system tracing of them#5688
Merged
a-robinson merged 1 commit intomainfrom Dec 15, 2025
Merged
Fix user tracing of DO SQL queries and add system tracing of them#5688a-robinson merged 1 commit intomainfrom
a-robinson merged 1 commit intomainfrom
Conversation
The user tracing of DO SQL queries was setting the rows_read tag too soon, before the cursor actually iterated over the result rows. This lead to under-reporting of rows_read in these trace spans. We can fix this by passing the span into the Cursor, allowing it to be finalized when the query itself is done. For some queries this will still be immediately because there aren't result rows to iterate over, but for others this will keep the span held open until either the result rows have all been read or the cursor has been canceled/closed. There's still one case here that's a little awkward: if the query throws an exception, we don't add any tags at all (either before this change or after it). We may want to add a try-catch here that adds an error span to the traces when running the sql statement throws an exception, but we can decide on that separately since it does come involve making the code more complex and adding a bit of runtime overhead.
6bc8846 to
35bba0f
Compare
justin-mp
approved these changes
Dec 15, 2025
Contributor
In general we don't have good coverage of the various error-paths yet, or a clear way of recording errors. I would like to make progress on this soon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The user tracing of DO SQL queries was setting the rows_read tag too soon, before the cursor actually iterated over the result rows. This lead to under-reporting of rows_read in these trace spans.
We can fix this by passing the span into the Cursor, allowing it to be finalized when the query itself is done. For some queries this will still be immediately because there aren't result rows to iterate over, but for others this will keep the span held open until either the result rows have all been read or the cursor has been canceled/closed.
There's still one case here that's a little awkward: if the query throws an exception, we don't add any tags at all (either before this change or after it). We may want to add a try-catch here that adds an error span to the traces when running the sql statement throws an exception, but we can decide on that separately since it does come involve making the code more complex and adding a bit of runtime overhead.
This is a follow-up to #5201