Skip to content

Commit cfbc2fd

Browse files
authored
fix(logs): remove Dispose from the public API surface area (#4424)
1 parent e06e7dc commit cfbc2fd

8 files changed

+12
-35
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
- Crontabs now support day names (MON-SUN) and allow step values and ranges to be combined ([#4407](https://github.com/getsentry/sentry-dotnet/pull/4407))
88
- Ensure the correct Sentry Cocoa SDK framework version is used on iOS ([#4411](https://github.com/getsentry/sentry-dotnet/pull/4411))
9+
- Experimental _Structured Logs_:
10+
- Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance. ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424))
911

1012
### Dependencies
1113

src/Sentry/Internal/DefaultSentryStructuredLogger.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Sentry.Internal;
55

6-
internal sealed class DefaultSentryStructuredLogger : SentryStructuredLogger
6+
internal sealed class DefaultSentryStructuredLogger : SentryStructuredLogger, IDisposable
77
{
88
private readonly IHub _hub;
99
private readonly SentryOptions _options;
@@ -105,13 +105,8 @@ protected internal override void Flush()
105105
}
106106

107107
/// <inheritdoc />
108-
protected override void Dispose(bool disposing)
108+
public void Dispose()
109109
{
110-
if (disposing)
111-
{
112-
_batchProcessor.Dispose();
113-
}
114-
115-
base.Dispose(disposing);
110+
_batchProcessor.Dispose();
116111
}
117112
}

src/Sentry/Internal/Hub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ public void Dispose()
832832
#endif
833833

834834
Logger.Flush();
835-
Logger.Dispose();
835+
(Logger as IDisposable)?.Dispose(); // see Sentry.Internal.DefaultSentryStructuredLogger
836836

837837
try
838838
{

src/Sentry/SentryStructuredLogger.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Sentry;
88
/// <para>This API is experimental and it may change in the future.</para>
99
/// </summary>
1010
[Experimental(DiagnosticId.ExperimentalFeature)]
11-
public abstract class SentryStructuredLogger : IDisposable
11+
public abstract class SentryStructuredLogger
1212
{
1313
internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, ISystemClock clock)
1414
=> Create(hub, options, clock, 100, TimeSpan.FromSeconds(5));
@@ -123,19 +123,4 @@ public void LogFatal(string template, object[]? parameters = null, Action<Sentry
123123
{
124124
CaptureLog(SentryLogLevel.Fatal, template, parameters, configureLog);
125125
}
126-
127-
/// <inheritdoc />
128-
public void Dispose()
129-
{
130-
Dispose(true);
131-
GC.SuppressFinalize(this);
132-
}
133-
134-
/// <summary>
135-
/// Override in inherited types to clean up managed and unmanaged resources.
136-
/// </summary>
137-
/// <param name="disposing">Invoked from <see cref="Dispose()"/> when <see langword="true"/>; Invoked from <c>Finalize</c> when <see langword="false"/>.</param>
138-
protected virtual void Dispose(bool disposing)
139-
{
140-
}
141126
}

test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,9 @@ namespace Sentry
10111011
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
10121012
}
10131013
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
1014-
public abstract class SentryStructuredLogger : System.IDisposable
1014+
public abstract class SentryStructuredLogger
10151015
{
10161016
protected abstract void CaptureLog(Sentry.SentryLog log);
1017-
public void Dispose() { }
1018-
protected virtual void Dispose(bool disposing) { }
10191017
protected abstract void Flush();
10201018
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
10211019
public void LogDebug(string template, object[]? parameters = null, System.Action<Sentry.SentryLog>? configureLog = null) { }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,9 @@ namespace Sentry
10111011
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
10121012
}
10131013
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
1014-
public abstract class SentryStructuredLogger : System.IDisposable
1014+
public abstract class SentryStructuredLogger
10151015
{
10161016
protected abstract void CaptureLog(Sentry.SentryLog log);
1017-
public void Dispose() { }
1018-
protected virtual void Dispose(bool disposing) { }
10191017
protected abstract void Flush();
10201018
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
10211019
public void LogDebug(string template, object[]? parameters = null, System.Action<Sentry.SentryLog>? configureLog = null) { }

test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,11 +971,9 @@ namespace Sentry
971971
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }
972972
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
973973
}
974-
public abstract class SentryStructuredLogger : System.IDisposable
974+
public abstract class SentryStructuredLogger
975975
{
976976
protected abstract void CaptureLog(Sentry.SentryLog log);
977-
public void Dispose() { }
978-
protected virtual void Dispose(bool disposing) { }
979977
protected abstract void Flush();
980978
public void LogDebug(string template, object[]? parameters = null, System.Action<Sentry.SentryLog>? configureLog = null) { }
981979
public void LogError(string template, object[]? parameters = null, System.Action<Sentry.SentryLog>? configureLog = null) { }

test/Sentry.Tests/SentryStructuredLoggerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ public void Dispose_BeforeLog_DoesNotCaptureEnvelope()
260260
_fixture.Options.Experimental.EnableLogs = true;
261261
var logger = _fixture.GetSut();
262262

263-
logger.Dispose();
263+
var defaultLogger = logger.Should().BeOfType<DefaultSentryStructuredLogger>().Which;
264+
defaultLogger.Dispose();
264265
logger.LogTrace("Template string with arguments: {0}, {1}, {2}, {3}", ["string", true, 1, 2.2], ConfigureLog);
265266

266267
_fixture.Hub.Received(0).CaptureEnvelope(Arg.Any<Envelope>());

0 commit comments

Comments
 (0)