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

Fix SQLClient unplanned behaviors #1179

Merged
merged 18 commits into from Sep 8, 2021
Merged

Conversation

lucas-zimerman
Copy link
Collaborator

This PR will fix the following issues found during dogfooding:

  • The first Query span is lost.
    : It happens because oftentimes the event got invoked before the Connection event.
    : FIX: create the Query on the Transaction if a connection is not found, afterwards, set the correct parent once the query is closed.

  • Missing Connection Span
    : The span was opened correctly but in case of data insertion or exclusion, the event related to closing the connection wasn't invoked, instead, another event gets invoked WriteTransactionCommitAfter.
    : FIX: Close the Connection span once WriteTransactionCommitAfter is invoked.

  • Many Connection Spans with the same connection Id:
    : Not sure why, perhaps since the connection might be shared, it closes to continue the execution of another query from another request and return to open the previous one once finished.
    : FIX: Set the connection Id to the Connection Span if another Span with the same Connection Id isn't found.

PS: Had to change the setter from the SpanTrace.parentId to internal in order to update the ParentID.

@lucas-zimerman lucas-zimerman added the Bug Something isn't working label Aug 30, 2021
@lucas-zimerman lucas-zimerman self-assigned this Aug 30, 2021
@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2021

Codecov Report

Merging #1179 (af93c89) into main (38bd5e2) will increase coverage by 0.02%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1179      +/-   ##
==========================================
+ Coverage   80.48%   80.51%   +0.02%     
==========================================
  Files         212      212              
  Lines        6851     6887      +36     
  Branches     1565     1571       +6     
==========================================
+ Hits         5514     5545      +31     
  Misses        823      823              
- Partials      514      519       +5     
Impacted Files Coverage Δ
...ce/Internals/DiagnosticSource/SentrySqlListener.cs 83.73% <84.61%> (-0.36%) ⬇️
src/Sentry/SpanTracer.cs 88.63% <100.00%> (+0.26%) ⬆️
...Internals/DiagnosticSource/SentryEFCoreListener.cs 83.01% <0.00%> (-1.89%) ⬇️
src/Sentry/GlobalSessionManager.cs 69.86% <0.00%> (+0.43%) ⬆️
src/Sentry/Internal/BackgroundWorker.cs 84.05% <0.00%> (+0.72%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38bd5e2...af93c89. Read the comment docs.

@lucas-zimerman lucas-zimerman added this to In Progress in v3.x Aug 30, 2021
@lucas-zimerman lucas-zimerman marked this pull request as ready for review August 31, 2021 18:16
@lucas-zimerman
Copy link
Collaborator Author

I had to initialize by default the Extra parameter from SpanTracer due to the chance of data loss when inserting data when the parameter wasn't created.
That was the main issue with the test since it relies on the extra parameters to correctly link the spans.

Comment on lines +158 to +159
if (connectionSpans?.Any(span => TryGetConnectionId(span) == connectionId) is false &&
connectionSpans.FirstOrDefault(span => TryGetOperationId(span) == operationId) is { } span)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why iterate over connectionSpans twice inside this if?
this can have 1k items in it, looks highly inefficient with so many LINQ calls per execution

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first iteration checks if there're any connection Spans with the given connection ID, if none is found it grabs the connection span with the given Operation ID and sets the connection ID.

I don't think you can perform both checks with only one iteration

@bruno-garcia bruno-garcia merged commit b55b55c into main Sep 8, 2021
@bruno-garcia bruno-garcia deleted the fix/sqlclient-firstspan-lost branch September 8, 2021 23:51
v3.x automation moved this from In Progress to Done Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
No open projects
v3.x
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants