Skip to content

Commit ec307a7

Browse files
fix: libmonosgen and libxamarin frames currently showing as inapp (#4960)
1 parent 7feb9a6 commit ec307a7

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- The SDK now logs a `Warning` instead of an `Error` when being ratelimited ([#4927](https://github.com/getsentry/sentry-dotnet/pull/4927))
8+
- `libmonosgen` and `libxamarin` frames no longer show as in-app ([#4960](https://github.com/getsentry/sentry-dotnet/pull/4960))
89

910
## 6.2.0-alpha.0
1011

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace Sentry.Internal;
2+
3+
internal static partial class InAppExcludeRegexes
4+
{
5+
// (^|[/\\]) — anchors to start of string or after a forward/backward slash
6+
// ([^/\\]*libmonosgen[^/\\]*) — last segment contains libmonosgen (no slashes before/after)
7+
// $ — end of string
8+
private const string LibMonoSgenPattern = @"(^|[/\\])([^/\\]*libmonosgen[^/\\]*)$";
9+
10+
// (^|[/\\]) — anchors to start of string or after a forward/backward slash
11+
// ([^/\\]*libxamarin[^/\\]*) — last segment contains libxamarin (no slashes before/after)
12+
// $ — end of string
13+
private const string LibXamarinPattern = @"(^|[/\\])([^/\\]*libxamarin[^/\\]*)$";
14+
15+
#if NET9_0_OR_GREATER
16+
[GeneratedRegex(LibMonoSgenPattern)]
17+
internal static partial Regex LibMonoSgen { get; }
18+
19+
[GeneratedRegex(LibXamarinPattern)]
20+
internal static partial Regex LibXamarin { get; }
21+
#elif NET8_0
22+
[GeneratedRegex(LibMonoSgenPattern)]
23+
private static partial Regex LibMonoSgenRegex();
24+
internal static Regex LibMonoSgen { get; } = LibMonoSgenRegex();
25+
26+
[GeneratedRegex(LibXamarinPattern)]
27+
private static partial Regex LibXamarinRegex();
28+
internal static Regex LibXamarin { get; } = LibXamarinRegex();
29+
#else
30+
internal static Regex LibMonoSgen { get; } = new(LibMonoSgenPattern, RegexOptions.Compiled);
31+
internal static Regex LibXamarin { get; } = new(LibXamarinPattern, RegexOptions.Compiled);
32+
#endif
33+
}
34+

src/Sentry/SentryOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,8 @@ internal static List<StringOrRegex> GetDefaultInAppExclude() =>
19041904
"Grpc",
19051905
"ServiceStack",
19061906
"Java.Interop",
1907+
InAppExcludeRegexes.LibMonoSgen,
1908+
InAppExcludeRegexes.LibXamarin
19071909
];
19081910

19091911
/// <summary>

test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,46 @@ public void ConfigureAppFrame_WithDefaultOptions_NotBuiltInIgnoredMarkedAsInApp(
239239
Assert.True(sut.InApp);
240240
}
241241

242+
[Theory]
243+
[InlineData("foolibmonosgenbar", false)]
244+
[InlineData("/data/Containers/Bundle/Application/Example.app/libmonosgen-dotnet-release.dylib", false)]
245+
[InlineData("/data/libmonosgen/something-else.dylib ", true)]
246+
public void ConfigureAppFrame_WithDefaultOptions_ExcludesMonoFrames(string package, bool expectedInApp)
247+
{
248+
var options = new SentryOptions();
249+
var sut = new SentryStackFrame
250+
{
251+
Function = "async void MainActivity.OnCreate(Bundle savedInstanceState)+(?) =\\u003E { }",
252+
Package = package
253+
};
254+
255+
// Act
256+
sut.ConfigureAppFrame(options);
257+
258+
// Assert
259+
Assert.Equal(expectedInApp, sut.InApp);
260+
}
261+
262+
[Theory]
263+
[InlineData("foolibxamarinbar", false)]
264+
[InlineData("/data/Containers/Bundle/Application/Example.app/libxamarin-dotnet-release.dylib", false)]
265+
[InlineData("/data/libxamarin/something-else.dylib ", true)]
266+
public void ConfigureAppFrame_WithDefaultOptions_ExcludesXamarinFrames(string package, bool expectedInApp)
267+
{
268+
var options = new SentryOptions();
269+
var sut = new SentryStackFrame
270+
{
271+
Function = "async void MainActivity.OnCreate(Bundle savedInstanceState)+(?) =\\u003E { }",
272+
Package = package
273+
};
274+
275+
// Act
276+
sut.ConfigureAppFrame(options);
277+
278+
// Assert
279+
Assert.Equal(expectedInApp, sut.InApp);
280+
}
281+
242282
[Fact]
243283
public void ConfigureAppFrame_WithDefaultOptions_JavaPackageNotInApp()
244284
{

0 commit comments

Comments
 (0)