From e3f158a0d90282dda4748b23dfd7f77bb0e40213 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sat, 31 May 2025 23:03:29 -0400 Subject: [PATCH 1/3] fix: system frames marked as inApp --- src/Sentry/SentryOptions.cs | 88 ++++++++++--------- src/Sentry/SentryStackFrame.cs | 4 + .../Exceptions/SentryStackFrameTests.cs | 52 +++++++++++ test/Sentry.Tests/SentryOptionsTests.cs | 20 +++++ 4 files changed, 122 insertions(+), 42 deletions(-) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index f8d728e0d3..88974f934c 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -1292,48 +1292,7 @@ public SentryOptions() Native = new NativeOptions(this); #endif - InAppExclude = new() { - "System", - "Mono", - "Sentry", - "Microsoft", - "MS", // MS.Win32, MS.Internal, etc: Desktop apps - "ABI.Microsoft", // MAUI - "WinRT", // WinRT, UWP, WinUI - "UIKit", // iOS / MacCatalyst - "Newtonsoft.Json", - "FSharp", - "Serilog", - "Giraffe", - "NLog", - "Npgsql", - "RabbitMQ", - "Hangfire", - "IdentityServer4", - "AWSSDK", - "Polly", - "Swashbuckle", - "FluentValidation", - "Autofac", - "Stackexchange.Redis", - "Dapper", - "RestSharp", - "SkiaSharp", - "IdentityModel", - "SqlitePclRaw", - "Xamarin", - "Android", // Ex: Android.Runtime.JNINativeWrapper... - "Google", - "MongoDB", - "Remotion.Linq", - "AutoMapper", - "Nest", - "Owin", - "MediatR", - "ICSharpCode", - "Grpc", - "ServiceStack" - }; + InAppExclude = GetDefaultInAppExclude(); #if DEBUG InAppInclude = new() @@ -1827,4 +1786,49 @@ internal void SetupLogging() // In the future, this will most likely contain process ID return TryGetDsnSpecificCacheDirectoryPath(); } + + internal static List GetDefaultInAppExclude() => + [ + "System", + "Mono", + "Sentry", + "Microsoft", + "MS", // MS.Win32, MS.Internal, etc: Desktop apps + "ABI.Microsoft", // MAUI + "WinRT", // WinRT, UWP, WinUI + "UIKit", // iOS / MacCatalyst + "Newtonsoft.Json", + "FSharp", + "Serilog", + "Giraffe", + "NLog", + "Npgsql", + "RabbitMQ", + "Hangfire", + "IdentityServer4", + "AWSSDK", + "Polly", + "Swashbuckle", + "FluentValidation", + "Autofac", + "Stackexchange.Redis", + "Dapper", + "RestSharp", + "SkiaSharp", + "IdentityModel", + "SqlitePclRaw", + "Xamarin", + "Android", // Ex: Android.Runtime.JNINativeWrapper... + "Google", + "MongoDB", + "Remotion.Linq", + "AutoMapper", + "Nest", + "Owin", + "MediatR", + "ICSharpCode", + "Grpc", + "ServiceStack", + "Java.Interop", + ]; } diff --git a/src/Sentry/SentryStackFrame.cs b/src/Sentry/SentryStackFrame.cs index 9384ee1e7e..bd6ba6519d 100644 --- a/src/Sentry/SentryStackFrame.cs +++ b/src/Sentry/SentryStackFrame.cs @@ -201,6 +201,10 @@ public void ConfigureAppFrame(SentryOptions options) { ConfigureAppFrame(options, Module, LazyModuleMatcher.Value); } + else if (!string.IsNullOrEmpty(Package)) + { + ConfigureAppFrame(options, Package, LazyModuleMatcher.Value); + } else if (!string.IsNullOrEmpty(Function)) { ConfigureAppFrame(options, Function, LazyFunctionMatcher.Value); diff --git a/test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs b/test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs index e6bc76aaa0..adc2c79526 100644 --- a/test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs +++ b/test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs @@ -222,6 +222,58 @@ public void ConfigureAppFrame_WithDefaultOptions_RecognizesSentryInternalFrame() Assert.False(sut.InApp); } + [Fact] + public void ConfigureAppFrame_WithDefaultOptions_NotBuiltInIgnoredMarkedAsInApp() + { + var options = new SentryOptions(); + var sut = new SentryStackFrame + { + Function = "async void MainActivity.OnCreate(Bundle savedInstanceState)+(?) =\\u003E { }", + Package = "SymbolCollector.Android, Version=1.23.0.0, Culture=neutral, PublicKeyToken=null" + }; + + // Act + sut.ConfigureAppFrame(options); + + // Assert + Assert.True(sut.InApp); + } + + [Fact] + public void ConfigureAppFrame_WithDefaultOptions_JavaPackageNotInApp() + { + var options = new SentryOptions(); + var sut = new SentryStackFrame + { + Function = "void StaticMethods.CallStaticVoidMethod(JniObjectReference, JniMethodInfo, JniArgumentValue*)", + Package = "Java.Interop, Version=9.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065" + }; + + // Act + sut.ConfigureAppFrame(options); + + // Assert + Assert.False(sut.InApp); + } + + [Fact] + public void ConfigureAppFrame_WithDefaultOptions_SystemPackageNotInApp() + { + var options = new SentryOptions(); + var sut = new SentryStackFrame + { + Function = "void Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, string path, bool isDirError)", + Package = "System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", + FileName = "Interop.IOErrors.cs", + }; + + // Act + sut.ConfigureAppFrame(options); + + // Assert + Assert.False(sut.InApp); + } + [Fact] public void ConfigureAppFrame_InAppAlreadySet_InAppIgnored() { diff --git a/test/Sentry.Tests/SentryOptionsTests.cs b/test/Sentry.Tests/SentryOptionsTests.cs index 7a12849443..32f1300ed3 100644 --- a/test/Sentry.Tests/SentryOptionsTests.cs +++ b/test/Sentry.Tests/SentryOptionsTests.cs @@ -334,6 +334,26 @@ public void AddInAppExclude_StoredInOptions() Assert.Contains(sut.InAppExclude!, actual => actual.ToString() == expected); } + [Fact] + public void AddInAppExclude_DoesNotOverrideDefaults() + { + var sut = new SentryOptions(); + const string expected = "test"; + sut.AddInAppExclude(expected); + Assert.All(SentryOptions.GetDefaultInAppExclude(), + item => Assert.Contains(item, sut.InAppExclude!)); + } + + [Fact] + public void InAppExcludes_IgnoresJavaFrames() + { + var sut = new SentryOptions(); + const string expected = "test"; + sut.AddInAppExclude(expected); + Assert.All(SentryOptions.GetDefaultInAppExclude(), + item => Assert.Contains(item, sut.InAppExclude!)); + } + [Fact] public void AddInAppExcludeRegex_StoredInOptions() { From 650b43aa43518961579d217efa8a3028069257d4 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sat, 31 May 2025 23:11:50 -0400 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62a9ade125..4ac513a69c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### Unreleased + +- Fix InApp Exclude for frames without Module by checking against frame's Package ([#4236](https://github.com/getsentry/sentry-dotnet/pull/4236)) + ## 5.9.0 ### Features From 74cb70874e9434af6d87048b01a2e92f83131705 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sun, 1 Jun 2025 11:54:05 -0400 Subject: [PATCH 3/3] Update test/Sentry.Tests/SentryOptionsTests.cs --- test/Sentry.Tests/SentryOptionsTests.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/Sentry.Tests/SentryOptionsTests.cs b/test/Sentry.Tests/SentryOptionsTests.cs index 32f1300ed3..7d53c1c9b5 100644 --- a/test/Sentry.Tests/SentryOptionsTests.cs +++ b/test/Sentry.Tests/SentryOptionsTests.cs @@ -344,16 +344,6 @@ public void AddInAppExclude_DoesNotOverrideDefaults() item => Assert.Contains(item, sut.InAppExclude!)); } - [Fact] - public void InAppExcludes_IgnoresJavaFrames() - { - var sut = new SentryOptions(); - const string expected = "test"; - sut.AddInAppExclude(expected); - Assert.All(SentryOptions.GetDefaultInAppExclude(), - item => Assert.Contains(item, sut.InAppExclude!)); - } - [Fact] public void AddInAppExcludeRegex_StoredInOptions() {