-
-
Notifications
You must be signed in to change notification settings - Fork 225
QOL: Allow finishing spans and transactions with using
#4627
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
base: version6
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## version6 #4627 +/- ##
===========================================
Coverage ? 73.08%
===========================================
Files ? 479
Lines ? 17389
Branches ? 3431
===========================================
Hits ? 12709
Misses ? 3821
Partials ? 859 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@Flash0ver I'm trying to force an analyzer warning for the <WarningsAsErrors>CA2000</WarningsAsErrors> However I can't seem to get it to work: The warning does appear for the undisposed use of Any ideas/thoughts? |
Oh ... perhaps I totally misunderstood CA2000 😟 DisposeObjectsBeforeLosingScope.cs Hmmm ... it seems that the CA2000-DiagnosticAnalyzer does some Control-Flow-Analysis, that either tries to "see through" the implementation and does not report when it can't statically figure it out, or just does not report for some usage patterns. var instance1 = new MyDisposable(); //CA2000
var instance2 = new MyFactory().CreateInstance(); //CA2000
var instance3 = MyFactory.CreateStatic(); //CA2000
var instance4 = MyFactory.Instance.CreateInstance(); // does not report CA2000
public sealed class MyDisposable : IDisposable
{
public void Dispose()
{
}
}
public interface IMyFactory
{
IDisposable CreateInstance();
}
public sealed class MyFactory : IMyFactory
{
public static IMyFactory Instance { get; } = new MyFactory();
public static IDisposable CreateStatic() => new MyDisposable();
public IDisposable CreateInstance() => new MyDisposable();
} Not sure if that analysis behavior is intended or not. Now, as a follow-up, I'm wondering: var transaction = new TransactionTracer(null!, null!); //CA2000
var span = new SpanTracer(null!, transaction, default, default, null!); //CA2000
span.Finish();
transaction.Finish(); Are there valid/intended usage scenarios to instantiate these types directly from user code, which would report |
I can't think of any scenario in which people would want to construct those manually... so I suspect not.
That's possibly the case yes... and without being able to reproduce the warning that it's supposed to suppress, it's relatively difficult to test. I think this PR might be ready for review then... |
test/Sentry.Tests/SpanTracerTests.cs
Outdated
} | ||
|
||
[Fact] | ||
public void Dispose_Finished_Finishes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Are part of the names here inverted from what each test case actually tests?
-public void Dispose_Finished_Finishes()
+public void Dispose_Unfinished_Finishes()
-public void Dispose_Unfinished_DoesNothing()
+public void Dispose_Finished_DoesNothing()
Or am I reading this wrongly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the CONTRIBUTING.md, the first part is the method Dispose
.
The second part is the context (Finished
or Unfinished
... this could be more elaborate like TransactionIsFinsished
and TransactionIsUnfinished
but I figured that was clear from both the SUT and the implementation.
The last part is the expectation (e.g. DoesNothing
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry ... I phrased it poorly.
What I meant was that Dispose_Finished_Finishes
should actually be Dispose_Unfinished_Finishes
,
and that Dispose_Unfinished_DoesNothing
should be Dispose_Finished_DoesNothing
.
It was just the name of the middle "context" portion what was flipped.
This is fixed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I believe that the names are still not quite correct:
Dispose_TransactionIsUnfinished_FinishesTransaction
Dispose_TransactionIsFinsished_DoesNothing
But both of these tests are in the SpanTracerTests.cs
.
I guess it should say "SpanIs(Un)Finished" and "FinishesSpan".
But I am actually fine with the shorter version ... as it does make sense within the context of the respective test type:
Dispose_Unfinished_Finishes
Dispose_Finished_DoesNothing
Since we have the same test names then on TransactionTracerTests.cs
as well.
Same test name, but in a different test class.
/// <inheritdoc /> | ||
public void Finish() | ||
{ | ||
// TODO: Replace with InterlockedBoolean once this has been merged into version6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO (as a "resolvable" comment)
Resolves #4321