From e99355cb9fa61ce8dd42f35a5e8d3679dcb5e312 Mon Sep 17 00:00:00 2001 From: Lucas Zimerman Fraulob Date: Tue, 22 Feb 2022 16:16:56 -0300 Subject: [PATCH 1/4] expose IsSystemModuleName as a public static function. --- .../Extensibility/SentryStackTraceFactory.cs | 14 ++++++++++---- .../ApiApprovalTests.Run.Core3_1.verified.txt | 1 + .../ApiApprovalTests.Run.DotNet5_0.verified.txt | 1 + .../ApiApprovalTests.Run.DotNet6_0.verified.txt | 1 + .../ApiApprovalTests.Run.Core2_1.verified.txt | 1 + .../ApiApprovalTests.Run.Core3_0.verified.txt | 1 + .../ApiApprovalTests.Run.Core3_1.verified.txt | 1 + .../ApiApprovalTests.Run.DotNet4_6.verified.txt | 1 + .../ApiApprovalTests.Run.DotNet5_0.verified.txt | 1 + .../ApiApprovalTests.Run.DotNet6_0.verified.txt | 1 + 10 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Sentry/Extensibility/SentryStackTraceFactory.cs b/src/Sentry/Extensibility/SentryStackTraceFactory.cs index bedd69bc65..857aa03a42 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.InApp ??= !IsSystemModuleName(frame.Module, _options); frame.FileName = stackFrame.GetFileName(); @@ -211,15 +211,21 @@ protected SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool deman protected virtual MethodBase? GetMethod(StackFrame stackFrame) => stackFrame.GetMethod(); - private bool IsSystemModuleName(string? moduleName) + /// + /// Inform if the given module name belongs to the System or not. + /// + /// The module name to be checked. + /// The Sentry options. + /// True if the module belongs to the System, false otherwise. + public static bool IsSystemModuleName(string? moduleName, SentryOptions options) { 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; + return options.InAppInclude?.Any(include => moduleName.StartsWith(include, StringComparison.Ordinal)) != true && + options.InAppExclude?.Any(exclude => moduleName.StartsWith(exclude, StringComparison.Ordinal)) == true; } /// 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..d47e79e743 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -1047,6 +1047,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http 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..dda4ba1f57 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -1047,6 +1047,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http 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..64a38ed275 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -1047,6 +1047,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt index cbda448e1a..fa417cbca9 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt @@ -1046,6 +1046,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt index d9285318df..e82f3d6fae 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt @@ -1046,6 +1046,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index 7286f06504..d47e79e743 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -1047,6 +1047,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt index 7e913fd13d..d1670003e7 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt @@ -1046,6 +1046,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index 821adeb115..dda4ba1f57 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -1047,6 +1047,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 0a373bee7c..64a38ed275 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -1047,6 +1047,7 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } + public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http From 1eb20403e4ab9bd1769c4c71a3b18e814936fd72 Mon Sep 17 00:00:00 2001 From: Lucas Zimerman Fraulob Date: Wed, 23 Feb 2022 11:25:07 -0300 Subject: [PATCH 2/4] IsSystemModuleName becomes ConfigureAppFrame. --- src/Sentry/Exceptions/SentryStackFrame.cs | 22 ++++++ .../Extensibility/SentryStackTraceFactory.cs | 19 +----- .../ApiApprovalTests.Run.Core3_1.verified.txt | 2 +- ...piApprovalTests.Run.DotNet5_0.verified.txt | 2 +- ...piApprovalTests.Run.DotNet6_0.verified.txt | 2 +- .../ApiApprovalTests.Run.Core2_1.verified.txt | 2 +- .../ApiApprovalTests.Run.Core3_0.verified.txt | 2 +- .../ApiApprovalTests.Run.Core3_1.verified.txt | 2 +- ...piApprovalTests.Run.DotNet4_6.verified.txt | 2 +- ...piApprovalTests.Run.DotNet5_0.verified.txt | 2 +- ...piApprovalTests.Run.DotNet6_0.verified.txt | 2 +- .../Exceptions/SentryStackFrameTests.cs | 68 +++++++++++++++++++ 12 files changed, 100 insertions(+), 27 deletions(-) diff --git a/src/Sentry/Exceptions/SentryStackFrame.cs b/src/Sentry/Exceptions/SentryStackFrame.cs index 9e2d880c72..48c54b8d6b 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,27 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) writer.WriteEndObject(); } + /// + /// Configures based on the InApp defined on SentryOptions. + /// + /// The Sentry options. + /// will remain with the same value if previously set. + public void ConfigureAppFrame(SentryOptions options) + { + var parameterName = Module ?? Function; + if (InApp != null) + { } + else if (string.IsNullOrEmpty(parameterName)) + { + InApp = true; + } + else + { + 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 857aa03a42..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, _options); + frame.ConfigureAppFrame(_options); frame.FileName = stackFrame.GetFileName(); @@ -211,23 +211,6 @@ protected SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool deman protected virtual MethodBase? GetMethod(StackFrame stackFrame) => stackFrame.GetMethod(); - /// - /// Inform if the given module name belongs to the System or not. - /// - /// The module name to be checked. - /// The Sentry options. - /// True if the module belongs to the System, false otherwise. - public static bool IsSystemModuleName(string? moduleName, SentryOptions options) - { - 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 d47e79e743..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) { } } @@ -1047,7 +1048,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http 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 dda4ba1f57..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) { } } @@ -1047,7 +1048,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http 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 64a38ed275..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) { } } @@ -1047,7 +1048,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt index fa417cbca9..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) { } } @@ -1046,7 +1047,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt index e82f3d6fae..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) { } } @@ -1046,7 +1047,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index d47e79e743..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) { } } @@ -1047,7 +1048,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt index d1670003e7..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) { } } @@ -1046,7 +1047,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index dda4ba1f57..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) { } } @@ -1047,7 +1048,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 64a38ed275..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) { } } @@ -1047,7 +1048,6 @@ namespace Sentry.Extensibility protected virtual System.Diagnostics.StackTrace CreateStackTrace(System.Exception? exception) { } protected virtual System.Reflection.MethodBase? GetMethod(System.Diagnostics.StackFrame stackFrame) { } protected Sentry.SentryStackFrame InternalCreateFrame(System.Diagnostics.StackFrame stackFrame, bool demangle) { } - public static bool IsSystemModuleName(string? moduleName, Sentry.SentryOptions options) { } } } namespace Sentry.Http 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."); + } } From 6ed45443ee453d3eb4e4a1ea7cdba1362a1c5310 Mon Sep 17 00:00:00 2001 From: Lucas Zimerman Fraulob Date: Fri, 25 Feb 2022 16:48:30 -0300 Subject: [PATCH 3/4] add nit. --- src/Sentry/Exceptions/SentryStackFrame.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Sentry/Exceptions/SentryStackFrame.cs b/src/Sentry/Exceptions/SentryStackFrame.cs index 48c54b8d6b..7a8151a6b9 100644 --- a/src/Sentry/Exceptions/SentryStackFrame.cs +++ b/src/Sentry/Exceptions/SentryStackFrame.cs @@ -170,16 +170,18 @@ public void ConfigureAppFrame(SentryOptions options) { var parameterName = Module ?? Function; if (InApp != null) - { } - else if (string.IsNullOrEmpty(parameterName)) { - InApp = true; + return; } - else + + if (string.IsNullOrEmpty(parameterName)) { - InApp = options.InAppInclude?.Any(include => parameterName.StartsWith(include, StringComparison.Ordinal)) == true || - options.InAppExclude?.Any(exclude => parameterName.StartsWith(exclude, StringComparison.Ordinal)) != true; + InApp = true; + return; } + + InApp = options.InAppInclude?.Any(include => parameterName.StartsWith(include, StringComparison.Ordinal)) == true || + options.InAppExclude?.Any(exclude => parameterName.StartsWith(exclude, StringComparison.Ordinal)) != true; } /// From 9d74cca7a96a1ea29b0724114792e1df89602bb6 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 26 Feb 2022 12:16:16 +1100 Subject: [PATCH 4/4] better xml doc --- src/Sentry/Exceptions/SentryStackFrame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry/Exceptions/SentryStackFrame.cs b/src/Sentry/Exceptions/SentryStackFrame.cs index 7a8151a6b9..85944f674c 100644 --- a/src/Sentry/Exceptions/SentryStackFrame.cs +++ b/src/Sentry/Exceptions/SentryStackFrame.cs @@ -162,7 +162,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) } /// - /// Configures based on the InApp defined on SentryOptions. + /// Configures based on the and or . /// /// The Sentry options. /// will remain with the same value if previously set.