Skip to content

Conversation

@Flash0ver
Copy link
Member

@Flash0ver Flash0ver commented Aug 1, 2025

closed
superseded by #4424

Flash0ver and others added 30 commits April 30, 2025 13:09
@Flash0ver Flash0ver self-assigned this Aug 1, 2025
@Flash0ver Flash0ver added the Logs label Aug 1, 2025
@Flash0ver
Copy link
Member Author

@sentry review

Comment on lines 108 to 111
public void Dispose()
{
if (disposing)
{
_batchProcessor.Dispose();
}

base.Dispose(disposing);
_batchProcessor.Dispose();
}
Copy link

Choose a reason for hiding this comment

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

The simplified Dispose() implementation is cleaner, but consider adding a disposed flag to prevent double disposal. The current implementation will call _batchProcessor.Dispose() multiple times if Dispose() is called repeatedly, which could potentially cause issues depending on the StructuredLogBatchProcessor implementation.

Suggested change
public void Dispose()
{
if (disposing)
{
_batchProcessor.Dispose();
}
base.Dispose(disposing);
_batchProcessor.Dispose();
}
private bool _disposed;public void Dispose(){if (_disposed){return;}_batchProcessor.Dispose();_disposed = true;}

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member Author

Choose a reason for hiding this comment

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

The only fields of DefaultSentryStructuredLogger that require cleanup is the StructuredLogBatchProcessor, which owns two IDisposable fields of type StructuredLogBatchBuffer.

According to the Guidelines:

To help ensure that resources are always cleaned up appropriately, a Dispose method should be idempotent, such that it's callable multiple times without throwing an exception. Furthermore, subsequent invocations of Dispose should do nothing.

See https://learn.microsoft.com/dotnet/standard/garbage-collection/implementing-dispose

We do own the implementation of the _batchProcessor field, where we can also ensure the Guideline is adhered to. So adding a private bool _disposed field to this type is possible, but not necessary.

I also double-checked the IDisposable implementation of the StructuredLogBatchBuffer type, and the IDisposable fields that it contains ... and all types do satisfy the Guideline.

Copy link
Member Author

@Flash0ver Flash0ver Aug 2, 2025

Choose a reason for hiding this comment

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

Note for Seer:

Diff

The suggestion is created off of the base / old code.
I expected the suggestion to be created off of the change / new code.

Formatting (C#)

The formatting of the suggested change is not idiomatic C# code.
It is suggested as a one-liner, where it should be suggested as such:

-private bool _disposed;public void Dispose(){if (_disposed){return;}_batchProcessor.Dispose();_disposed = true;}
+private bool _disposed;
+
+public void Dispose()
+{
+    if (_disposed)
+    {
+        return;
+    }
+
+    _batchProcessor.Dispose();
+    _disposed = true;
+}

Note

Technically, the suggestion is correct!
I opt to dismiss is though because it is not necessary in this case.

Base automatically changed from feat/logs-microsoft-extensions-logging to feat/logs August 6, 2025 12:47
Base automatically changed from feat/logs to main August 7, 2025 12:09
@Flash0ver Flash0ver closed this Aug 9, 2025
@Flash0ver Flash0ver deleted the fix/logs-dispose branch August 9, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants