Skip to content

Commit b6fb323

Browse files
authored
fix(logs): flush Logger on UnhandledException that IsTerminating (#4425)
1 parent f7ec5ee commit b6fb323

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Experimental _Structured Logs_:
8+
- Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance. ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424))
9+
- Ensure all buffered logs are sent to Sentry when the application terminates unexpectedly. ([#4425](https://github.com/getsentry/sentry-dotnet/pull/4425))
10+
311
## 5.14.1
412

513
### Fixes
614

715
- 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))
816
- 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))
1117

1218
### Dependencies
1319

src/Sentry/Internal/Hub.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ public async Task FlushAsync(TimeSpan timeout)
798798
{
799799
try
800800
{
801+
Logger.Flush();
801802
await CurrentClient.FlushAsync(timeout).ConfigureAwait(false);
802803
}
803804
catch (Exception e)

test/Sentry.Tests/HubTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,31 @@ public void Logger_DisableAfterCreate_HasNoEffect()
16241624
hub.Logger.Should().BeOfType<DefaultSentryStructuredLogger>();
16251625
}
16261626

1627+
[Fact]
1628+
public async Task Logger_FlushAsync_DoesCaptureLog()
1629+
{
1630+
// Arrange
1631+
_fixture.Options.Experimental.EnableLogs = true;
1632+
var hub = _fixture.GetSut();
1633+
1634+
// Act
1635+
hub.Logger.LogWarning("Message");
1636+
await hub.FlushAsync();
1637+
1638+
// Assert
1639+
_fixture.Client.Received(1).CaptureEnvelope(
1640+
Arg.Is<Envelope>(envelope =>
1641+
envelope.Items.Single(item => item.Header["type"].Equals("log")).Payload.GetType().IsAssignableFrom(typeof(JsonSerializable))
1642+
)
1643+
);
1644+
await _fixture.Client.Received(1).FlushAsync(
1645+
Arg.Is<TimeSpan>(timeout =>
1646+
timeout.Equals(_fixture.Options.FlushTimeout)
1647+
)
1648+
);
1649+
hub.Logger.Should().BeOfType<DefaultSentryStructuredLogger>();
1650+
}
1651+
16271652
[Fact]
16281653
public void Logger_Dispose_DoesCaptureLog()
16291654
{
@@ -1641,6 +1666,11 @@ public void Logger_Dispose_DoesCaptureLog()
16411666
envelope.Items.Single(item => item.Header["type"].Equals("log")).Payload.GetType().IsAssignableFrom(typeof(JsonSerializable))
16421667
)
16431668
);
1669+
_fixture.Client.Received(1).FlushAsync(
1670+
Arg.Is<TimeSpan>(timeout =>
1671+
timeout.Equals(_fixture.Options.ShutdownTimeout)
1672+
)
1673+
);
16441674
hub.Logger.Should().BeOfType<DefaultSentryStructuredLogger>();
16451675
}
16461676

0 commit comments

Comments
 (0)