Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- 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))
- Ensure the correct Sentry Cocoa SDK framework version is used on iOS ([#4411](https://github.com/getsentry/sentry-dotnet/pull/4411))
- Experimental _Structured Logs_:
- Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance. ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424))

### Dependencies

Expand Down
11 changes: 3 additions & 8 deletions src/Sentry/Internal/DefaultSentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Sentry.Internal;

internal sealed class DefaultSentryStructuredLogger : SentryStructuredLogger
internal sealed class DefaultSentryStructuredLogger : SentryStructuredLogger, IDisposable
{
private readonly IHub _hub;
private readonly SentryOptions _options;
Expand Down Expand Up @@ -105,13 +105,8 @@ protected internal override void Flush()
}

/// <inheritdoc />
protected override void Dispose(bool disposing)
public void Dispose()
{
if (disposing)
{
_batchProcessor.Dispose();
}

base.Dispose(disposing);
_batchProcessor.Dispose();
}
}
2 changes: 1 addition & 1 deletion src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ public void Dispose()
#endif

Logger.Flush();
Logger.Dispose();
(Logger as IDisposable)?.Dispose(); // see Sentry.Internal.DefaultSentryStructuredLogger

try
{
Expand Down
17 changes: 1 addition & 16 deletions src/Sentry/SentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Sentry;
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public abstract class SentryStructuredLogger : IDisposable
public abstract class SentryStructuredLogger
{
internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, ISystemClock clock)
=> Create(hub, options, clock, 100, TimeSpan.FromSeconds(5));
Expand Down Expand Up @@ -123,19 +123,4 @@ public void LogFatal(string template, object[]? parameters = null, Action<Sentry
{
CaptureLog(SentryLogLevel.Fatal, template, parameters, configureLog);
}

/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Override in inherited types to clean up managed and unmanaged resources.
/// </summary>
/// <param name="disposing">Invoked from <see cref="Dispose()"/> when <see langword="true"/>; Invoked from <c>Finalize</c> when <see langword="false"/>.</param>
protected virtual void Dispose(bool disposing)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1011,11 +1011,9 @@ namespace Sentry
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
}
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
public abstract class SentryStructuredLogger : System.IDisposable
public abstract class SentryStructuredLogger
{
protected abstract void CaptureLog(Sentry.SentryLog log);
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
protected abstract void Flush();
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
public void LogDebug(string template, object[]? parameters = null, System.Action<Sentry.SentryLog>? configureLog = null) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,11 +1011,9 @@ namespace Sentry
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
}
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
public abstract class SentryStructuredLogger : System.IDisposable
public abstract class SentryStructuredLogger
{
protected abstract void CaptureLog(Sentry.SentryLog log);
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
protected abstract void Flush();
[System.Diagnostics.CodeAnalysis.Experimental("SENTRY0001")]
public void LogDebug(string template, object[]? parameters = null, System.Action<Sentry.SentryLog>? configureLog = null) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,9 @@ namespace Sentry
public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { }
public static Sentry.SentryStackTrace FromJson(System.Text.Json.JsonElement json) { }
}
public abstract class SentryStructuredLogger : System.IDisposable
public abstract class SentryStructuredLogger
{
protected abstract void CaptureLog(Sentry.SentryLog log);
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
protected abstract void Flush();
public void LogDebug(string template, object[]? parameters = null, System.Action<Sentry.SentryLog>? configureLog = null) { }
public void LogError(string template, object[]? parameters = null, System.Action<Sentry.SentryLog>? configureLog = null) { }
Expand Down
3 changes: 2 additions & 1 deletion test/Sentry.Tests/SentryStructuredLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ public void Dispose_BeforeLog_DoesNotCaptureEnvelope()
_fixture.Options.Experimental.EnableLogs = true;
var logger = _fixture.GetSut();

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

_fixture.Hub.Received(0).CaptureEnvelope(Arg.Any<Envelope>());
Expand Down
Loading