diff --git a/CHANGELOG.md b/CHANGELOG.md index 35588e2719..72068656ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Fix error with `ConcurrentHashMap` on Android <= 9 ([#1761](https://github.com/getsentry/sentry-dotnet/pull/1761)) - Minor improvements to `BackgroundWorker` ([#1773](https://github.com/getsentry/sentry-dotnet/pull/1773)) - Make GzipRequestBodyHandler respect async ([#1776](https://github.com/getsentry/sentry-dotnet/pull/1776)) +- Fix exceptions on background thread not reported in Unity ([#1794](https://github.com/getsentry/sentry-dotnet/pull/1794)) ## 3.19.0 diff --git a/src/Sentry/Integrations/AppDomainUnhandledExceptionIntegration.cs b/src/Sentry/Integrations/AppDomainUnhandledExceptionIntegration.cs index d50c40aeab..d4a83046d2 100644 --- a/src/Sentry/Integrations/AppDomainUnhandledExceptionIntegration.cs +++ b/src/Sentry/Integrations/AppDomainUnhandledExceptionIntegration.cs @@ -10,13 +10,15 @@ internal class AppDomainUnhandledExceptionIntegration : ISdkIntegration { private readonly IAppDomain _appDomain; private IHub? _hub; + private SentryOptions? _options; internal AppDomainUnhandledExceptionIntegration(IAppDomain? appDomain = null) => _appDomain = appDomain ?? AppDomainAdapter.Instance; - public void Register(IHub hub, SentryOptions _) + public void Register(IHub hub, SentryOptions options) { _hub = hub; + _options = options; _appDomain.UnhandledException += Handle; } @@ -36,7 +38,7 @@ internal void Handle(object sender, UnhandledExceptionEventArgs e) if (e.IsTerminating) { - (_hub as IDisposable)?.Dispose(); + _hub?.FlushAsync(_options!.ShutdownTimeout).GetAwaiter().GetResult(); } } } diff --git a/test/Sentry.Tests/AppDomainUnhandledExceptionIntegrationTests.cs b/test/Sentry.Tests/AppDomainUnhandledExceptionIntegrationTests.cs index 39648c6fae..2ff82b981c 100644 --- a/test/Sentry.Tests/AppDomainUnhandledExceptionIntegrationTests.cs +++ b/test/Sentry.Tests/AppDomainUnhandledExceptionIntegrationTests.cs @@ -39,15 +39,14 @@ public void Handle_NoException_NoCaptureEvent() } [Fact] - public void Handle_TerminatingTrue_DisposesHub() + public void Handle_TerminatingTrue_FlushesHub() { var sut = _fixture.GetSut(); sut.Register(_fixture.Hub, SentryOptions); sut.Handle(this, new UnhandledExceptionEventArgs(new Exception(), true)); - var disposableHub = _fixture.Hub as IDisposable; - disposableHub.Received(1).Dispose(); + _fixture.Hub.Received(1).FlushAsync(Arg.Any()); } [Fact] @@ -70,15 +69,14 @@ public void Handle_TerminatingTrue_IsHandledFalse() } [Fact] - public void Handle_TerminatingTrue_NoException_DisposesHub() + public void Handle_TerminatingTrue_NoException_FlushesHub() { var sut = _fixture.GetSut(); sut.Register(_fixture.Hub, SentryOptions); sut.Handle(this, new UnhandledExceptionEventArgs(null, true)); - var disposableHub = _fixture.Hub as IDisposable; - disposableHub.Received(1).Dispose(); + _fixture.Hub.Received(1).FlushAsync(Arg.Any()); } [Fact]