diff --git a/src/Sentry/Exceptions/SentryStackFrame.cs b/src/Sentry/Exceptions/SentryStackFrame.cs index 9e2d880c72..85944f674c 100644 --- a/src/Sentry/Exceptions/SentryStackFrame.cs +++ b/src/Sentry/Exceptions/SentryStackFrame.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; @@ -160,6 +161,29 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) writer.WriteEndObject(); } + /// + /// Configures based on the and or . + /// + /// The Sentry options. + /// will remain with the same value if previously set. + public void ConfigureAppFrame(SentryOptions options) + { + var parameterName = Module ?? Function; + if (InApp != null) + { + return; + } + + if (string.IsNullOrEmpty(parameterName)) + { + InApp = true; + return; + } + + InApp = options.InAppInclude?.Any(include => parameterName.StartsWith(include, StringComparison.Ordinal)) == true || + options.InAppExclude?.Any(exclude => parameterName.StartsWith(exclude, StringComparison.Ordinal)) != true; + } + /// /// Parses from JSON. /// diff --git a/src/Sentry/Extensibility/SentryStackTraceFactory.cs b/src/Sentry/Extensibility/SentryStackTraceFactory.cs index bedd69bc65..51ba4d81ca 100644 --- a/src/Sentry/Extensibility/SentryStackTraceFactory.cs +++ b/src/Sentry/Extensibility/SentryStackTraceFactory.cs @@ -164,7 +164,7 @@ protected SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool deman } } - frame.InApp ??= !IsSystemModuleName(frame.Module); + frame.ConfigureAppFrame(_options); frame.FileName = stackFrame.GetFileName(); @@ -211,17 +211,6 @@ protected SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool deman protected virtual MethodBase? GetMethod(StackFrame stackFrame) => stackFrame.GetMethod(); - private bool IsSystemModuleName(string? moduleName) - { - if (string.IsNullOrEmpty(moduleName)) - { - return false; - } - - return _options.InAppInclude?.Any(include => moduleName.StartsWith(include, StringComparison.Ordinal)) != true && - _options.InAppExclude?.Any(exclude => moduleName.StartsWith(exclude, StringComparison.Ordinal)) == true; - } - /// /// Clean up function and module names produced from `async` state machine calls. /// 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 7286f06504..84e5543651 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -573,6 +573,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } 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 821adeb115..2f9d342323 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -573,6 +573,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } 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 0a373bee7c..4ae510b308 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -573,6 +573,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt index cbda448e1a..27ec145a47 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt @@ -572,6 +572,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt index d9285318df..f21ea4b9ea 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt @@ -572,6 +572,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index 7286f06504..84e5543651 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -573,6 +573,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt index 7e913fd13d..ca4b35033f 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt @@ -572,6 +572,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index 821adeb115..2f9d342323 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -573,6 +573,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 0a373bee7c..4ae510b308 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -573,6 +573,7 @@ namespace Sentry public System.Collections.Generic.IList PreContext { get; } public long? SymbolAddress { get; set; } public System.Collections.Generic.IDictionary Vars { get; } + public void ConfigureAppFrame(Sentry.SentryOptions options) { } public void WriteTo(System.Text.Json.Utf8JsonWriter writer, Sentry.Extensibility.IDiagnosticLogger? logger) { } public static Sentry.SentryStackFrame FromJson(System.Text.Json.JsonElement json) { } } diff --git a/test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs b/test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs index 2ab4f99653..8acf106f4f 100644 --- a/test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs +++ b/test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs @@ -83,4 +83,72 @@ public void FramesOmitted_Getter_NotNull() var sut = new SentryStackFrame(); Assert.NotNull(sut.FramesOmitted); } + + [Fact] + public void ConfigureAppFrame_InAppIncludeMatches_TrueSet() + { + // Arrange + var module = "IncludedModule"; + var sut = new SentryStackFrame(); + sut.Module = module; + var options = new SentryOptions(); + options.AddInAppInclude(module); + + // Act + sut.ConfigureAppFrame(options); + + // Assert + Assert.True(sut.InApp); + } + + [Fact] + public void ConfigureAppFrame_InAppExcludeMatches_TrueSet() + { + // Arrange + var module = "ExcludedModule"; + var sut = new SentryStackFrame(); + sut.Module = module; + var options = new SentryOptions(); + options.AddInAppExclude(module); + + // Act + sut.ConfigureAppFrame(options); + + // Assert + Assert.False(sut.InApp); + } + + [Fact] + public void ConfigureAppFrame_InAppRuleDoesntMatch_TrueSet() + { + // Arrange + var module = "AppModule"; + var sut = new SentryStackFrame(); + sut.Module = module; + var options = new SentryOptions(); + + // Act + sut.ConfigureAppFrame(options); + + // Assert + Assert.True(sut.InApp); + } + + [Fact] + public void ConfigureAppFrame_InAppAlreadySet_InAppIgnored() + { + // Arrange + var module = "ExcludedModule"; + var sut = new SentryStackFrame(); + sut.Module = module; + var options = new SentryOptions(); + options.AddInAppExclude(module); + sut.InApp = true; + + // Act + sut.ConfigureAppFrame(options); + + // Assert + Assert.True(sut.InApp, "InApp started as true but ConfigureAppFrame changed it to false."); + } }