diff --git a/CHANGELOG.md b/CHANGELOG.md index da18169d99..e3a1ad795d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Flatten AggregateException ([#1672](https://github.com/getsentry/sentry-dotnet/pull/1672)) + ### Features - Move tunnel functionality into Sentry.AspNetCore ([#1645](https://github.com/getsentry/sentry-dotnet/pull/1645)) diff --git a/src/Sentry/Internal/MainExceptionProcessor.cs b/src/Sentry/Internal/MainExceptionProcessor.cs index 8b057ce2e8..433e65e410 100644 --- a/src/Sentry/Internal/MainExceptionProcessor.cs +++ b/src/Sentry/Internal/MainExceptionProcessor.cs @@ -88,6 +88,11 @@ internal IEnumerable CreateSentryException(Exception exception) { yield return inner; } + + if (!_options.KeepAggregateException) + { + yield break; + } } else if (exception.InnerException != null) { diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index 63c9e0f1cb..13dd8f976e 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -591,6 +591,13 @@ public StackTraceMode StackTraceMode /// public Func? CrashedLastRun { get; set; } + /// + /// Keep in sentry logging. + /// The default behaviour is to only log and not include the root . + /// Set KeepAggregateException to true to include the root . + /// + public bool KeepAggregateException { get; set; } + /// /// Creates a new instance of /// diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 1134a37a58..03dafc89d8 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -41,7 +41,7 @@ - + diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index d43fc70dc3..737547320e 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -485,6 +485,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index faf8a17676..9a0a8f1214 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -485,6 +485,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index a1f4b1cd45..076d83e5f4 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -485,6 +485,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt index 3c980fcf81..1d165f1d77 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt @@ -485,6 +485,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt index 5077c9700e..486f241bab 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt @@ -485,6 +485,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index d43fc70dc3..737547320e 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -485,6 +485,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt index 8c9849f874..adaa67a5e9 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt @@ -484,6 +484,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index faf8a17676..9a0a8f1214 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -485,6 +485,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index a1f4b1cd45..076d83e5f4 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -485,6 +485,7 @@ namespace Sentry public System.TimeSpan InitCacheFlushTimeout { get; set; } public bool IsEnvironmentUser { get; set; } public bool IsGlobalModeEnabled { get; set; } + public bool KeepAggregateException { get; set; } public long MaxAttachmentSize { get; set; } public int MaxBreadcrumbs { get; set; } public int MaxCacheItems { get; set; } diff --git a/test/Sentry.Tests/Internals/MainExceptionProcessorTests.CreateSentryException_Aggregate.verified.txt b/test/Sentry.Tests/Internals/MainExceptionProcessorTests.CreateSentryException_Aggregate.verified.txt new file mode 100644 index 0000000000..c93b97f626 --- /dev/null +++ b/test/Sentry.Tests/Internals/MainExceptionProcessorTests.CreateSentryException_Aggregate.verified.txt @@ -0,0 +1,14 @@ +[ + { + Type: System.Exception, + Value: Inner message1, + ThreadId: Id_1, + Mechanism: {} + }, + { + Type: System.Exception, + Value: Inner message2, + ThreadId: Id_1, + Mechanism: {} + } +] \ No newline at end of file diff --git a/test/Sentry.Tests/Internals/MainExceptionProcessorTests.CreateSentryException_Aggregate_Keep.verified.txt b/test/Sentry.Tests/Internals/MainExceptionProcessorTests.CreateSentryException_Aggregate_Keep.verified.txt new file mode 100644 index 0000000000..f7734afece --- /dev/null +++ b/test/Sentry.Tests/Internals/MainExceptionProcessorTests.CreateSentryException_Aggregate_Keep.verified.txt @@ -0,0 +1,19 @@ +[ + { + Type: System.Exception, + Value: Inner message1, + ThreadId: Id_1, + Mechanism: {} + }, + { + Type: System.Exception, + Value: Inner message2, + ThreadId: Id_1, + Mechanism: {} + }, + { + Type: System.AggregateException, + ThreadId: Id_1, + Mechanism: {} + } +] \ No newline at end of file diff --git a/test/Sentry.Tests/Internals/MainExceptionProcessorTests.cs b/test/Sentry.Tests/Internals/MainExceptionProcessorTests.cs index 296246f98e..18ba0e979d 100644 --- a/test/Sentry.Tests/Internals/MainExceptionProcessorTests.cs +++ b/test/Sentry.Tests/Internals/MainExceptionProcessorTests.cs @@ -1,5 +1,6 @@ namespace Sentry.Tests.Internals; +[UsesVerify] public class MainExceptionProcessorTests { private class Fixture @@ -149,7 +150,38 @@ public void CreateSentryException_DataHasObjectAsKey_ItemIgnored() } [Fact] - public void Process_HasTagsOnExceptionData_TagsSetted() + public Task CreateSentryException_Aggregate() + { + var sut = _fixture.GetSut(); + var aggregateException = BuildAggregateException(); + + var sentryException = sut.CreateSentryException(aggregateException); + + return Verify(sentryException); + } + + [Fact] + public Task CreateSentryException_Aggregate_Keep() + { + _fixture.SentryOptions.KeepAggregateException = true; + var sut = _fixture.GetSut(); + var aggregateException = BuildAggregateException(); + + var sentryException = sut.CreateSentryException(aggregateException); + + return Verify(sentryException) + .ScrubLines(x => x.Contains("One or more errors occurred")); + } + + private static AggregateException BuildAggregateException() + { + return new AggregateException( + new Exception("Inner message1"), + new Exception("Inner message2")); + } + + [Fact] + public void Process_HasTagsOnExceptionData_TagsSet() { //Assert var sut = _fixture.GetSut(); diff --git a/test/Sentry.Tests/ModuleInit.cs b/test/Sentry.Tests/ModuleInit.cs index c288d7b567..6e6dda955d 100644 --- a/test/Sentry.Tests/ModuleInit.cs +++ b/test/Sentry.Tests/ModuleInit.cs @@ -6,6 +6,7 @@ public static class ModuleInit public static void Init() { VerifyDiffPlex.Initialize(); + VerifierSettings.IgnoreMember(_=>_.Module); VerifierSettings.MemberConverter>( target => target.Data, (_, value) =>