Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten aggregate exception #1672

Merged
merged 4 commits into from
May 26, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions src/Sentry/Internal/MainExceptionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ internal IEnumerable<SentryException> CreateSentryException(Exception exception)
{
yield return inner;
}

if (!_options.KeepAggregateException)
{
yield break;
}
}
else if (exception.InnerException != null)
{
Expand Down
7 changes: 7 additions & 0 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,13 @@ public StackTraceMode StackTraceMode
/// </summary>
public Func<bool>? CrashedLastRun { get; set; }

/// <summary>
/// Keep <see cref="AggregateException"/> in sentry logging.
/// The default behaviour is to only log <see cref="AggregateException.InnerExceptions"/> and not include the root <see cref="AggregateException"/>.
/// Set KeepAggregateException to true to include the root <see cref="AggregateException"/>.
/// </summary>
public bool KeepAggregateException { get; set; }

/// <summary>
/// Creates a new instance of <see cref="SentryOptions"/>
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="Verify.Xunit" Version="16.7.0" />
<PackageReference Include="Verify.Xunit" Version="16.8.2" />
<PackageReference Include="Verify.DiffPlex" Version="1.2.0" />
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="1.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
Type: System.Exception,
Value: Inner message1,
ThreadId: Id_1,
Mechanism: {}
},
{
Type: System.Exception,
Value: Inner message2,
ThreadId: Id_1,
Mechanism: {}
}
]
Original file line number Diff line number Diff line change
@@ -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: {}
}
]
34 changes: 33 additions & 1 deletion test/Sentry.Tests/Internals/MainExceptionProcessorTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Sentry.Tests.Internals;

[UsesVerify]
public class MainExceptionProcessorTests
{
private class Fixture
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/Sentry.Tests/ModuleInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static class ModuleInit
public static void Init()
{
VerifyDiffPlex.Initialize();
VerifierSettings.IgnoreMember<SentryException>(_=>_.Module);
VerifierSettings.MemberConverter<Breadcrumb, IReadOnlyDictionary<string, string>>(
target => target.Data,
(_, value) =>
Expand Down