-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Fix warning caused by db connection span closed prematurely #2068
Merged
Conversation
This file contains 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
FYI, here's the log output of
After the changes, the warning is gone.
|
mattjohnsonpint
commented
Nov 30, 2022
src/Sentry.DiagnosticSource/Internal/DiagnosticSource/SentrySqlListener.cs
Show resolved
Hide resolved
mattjohnsonpint
commented
Nov 30, 2022
test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.Logging.DotNet6_0.verified.txt
Show resolved
Hide resolved
mattjohnsonpint
commented
Nov 30, 2022
test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.Logging.DotNet6_0.verified.txt
Show resolved
Hide resolved
mattjohnsonpint
commented
Nov 30, 2022
test/Sentry.DiagnosticSource.IntegrationTests/SqlListenerTests.verify.cs
Show resolved
Hide resolved
mattjohnsonpint
commented
Nov 30, 2022
bruno-garcia
approved these changes
Dec 2, 2022
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.
In #1179, some logic was added to close connection spans when
WriteTransactionCommitAfter
. The comments from the state thatWriteConnectionCloseAfter
was not called in certain cases. However, after investigating, I believe this was an incorrect assumption. The actual reasonWriteConnectionCloseAfter
may not fire is when the connection is actually held open. Committing a transaction isn't a good place to close the connection span, because more than one command (and more than one transaction) can execute on a given connection.Indeed, our own
RecordsEf
integration test (added later) was showing the connection span warning, because both theWriteTransactionCommitAfter
andWriteConnectionCloseAfter
events were firing. Since the first one closed the connection span, the second one failed to find an unfinished span.Therefore, the fix is to remove that logic and close the connection span only with
WriteConnectionCloseAfter
.Also, some of our integration tests were not capturing the connection span correctly in the first place - because they were re-using a connection that was opened automatically by creating the LocalDB instance, which was done before the hub was initialized. I fixed these tests such that they open, use, and close a new db connection within the Sentry transaction being captured.
As a sanity check, I ran the new tests with the versions of EF Core and SQL Client that were used at the time #1179 was authored, and I was not able to get any scenario where
WriteConnectionCloseAfter
was not called. Thus, it wasn't related to some other older EF/SQL bug.Also, a nice side-effect of this change is that connection statistics are now captured in more cases.
I'll drop some more comments inline.
Should fix #2060 (at least in part)