Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

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

## 6.2.0-alpha.0

Expand Down
34 changes: 34 additions & 0 deletions src/Sentry/Internal/InAppExcludeRegexes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Sentry.Internal;

internal static partial class InAppExcludeRegexes
{
// (^|[/\\]) — anchors to start of string or after a forward/backward slash
// ([^/\\]*libmonosgen[^/\\]*) — last segment contains libmonosgen (no slashes before/after)
// $ — end of string
private const string LibMonoSgenPattern = @"(^|[/\\])([^/\\]*libmonosgen[^/\\]*)$";

// (^|[/\\]) — anchors to start of string or after a forward/backward slash
// ([^/\\]*libxamarin[^/\\]*) — last segment contains libxamarin (no slashes before/after)
// $ — end of string
private const string LibXamarinPattern = @"(^|[/\\])([^/\\]*libxamarin[^/\\]*)$";

#if NET9_0_OR_GREATER
[GeneratedRegex(LibMonoSgenPattern)]
internal static partial Regex LibMonoSgen { get; }

[GeneratedRegex(LibXamarinPattern)]
internal static partial Regex LibXamarin { get; }
Comment on lines +15 to +20
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: use RegexOptions.ExplicitCapture and/or RegexOptions.CultureInvariant

re RegexOptions.ExplicitCapture

When the Regex-Pattern includes parentheses (( and )), these are also "Capture Groups" per default. But not sure if we actually consume these automatically captures Groups ... where we may do some work that is not necessarily needed ... in other words: impacting performance slightly.

We have three IStringOrRegexMatcher

  • DelimitedPrefixOrPatternMatcher
    • calls Regex.Matches
  • PrefixOrPatternMatcher
    • calls Regex.IsMatch
  • SubstringOrPatternMatcher
    • calls Regex.IsMatch

On the other hand ... although we are not actively using Capture Groups right now ... we might in the future and then the In-App detection might not work as expected.

I believe I'm actually talking myself out of this change now ... considering it's only about performance, not correctness.

re RegexOptions.CultureInvariant

Not sure if adding this option would actually be about correctness in our case ... perhaps also only performance.


I guess keeping the Regex-Options as they are (i.e. RegexOptions.Compiled for non-source-generated Regex) seems to be fine.

What do you think?

#elif NET8_0
[GeneratedRegex(LibMonoSgenPattern)]
private static partial Regex LibMonoSgenRegex();
internal static Regex LibMonoSgen { get; } = LibMonoSgenRegex();

[GeneratedRegex(LibXamarinPattern)]
private static partial Regex LibXamarinRegex();
internal static Regex LibXamarin { get; } = LibXamarinRegex();
#else
internal static Regex LibMonoSgen { get; } = new(LibMonoSgenPattern, RegexOptions.Compiled);
internal static Regex LibXamarin { get; } = new(LibXamarinPattern, RegexOptions.Compiled);
#endif
}

2 changes: 2 additions & 0 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,8 @@ internal static List<StringOrRegex> GetDefaultInAppExclude() =>
"Grpc",
"ServiceStack",
"Java.Interop",
InAppExcludeRegexes.LibMonoSgen,
InAppExcludeRegexes.LibXamarin
];

/// <summary>
Expand Down
40 changes: 40 additions & 0 deletions test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,46 @@ public void ConfigureAppFrame_WithDefaultOptions_NotBuiltInIgnoredMarkedAsInApp(
Assert.True(sut.InApp);
}

[Theory]
[InlineData("foolibmonosgenbar", false)]
[InlineData("/data/Containers/Bundle/Application/Example.app/libmonosgen-dotnet-release.dylib", false)]
[InlineData("/data/libmonosgen/something-else.dylib ", true)]
public void ConfigureAppFrame_WithDefaultOptions_ExcludesMonoFrames(string package, bool expectedInApp)
{
var options = new SentryOptions();
var sut = new SentryStackFrame
{
Function = "async void MainActivity.OnCreate(Bundle savedInstanceState)+(?) =\\u003E { }",
Package = package
};

// Act
sut.ConfigureAppFrame(options);

// Assert
Assert.Equal(expectedInApp, sut.InApp);
}

[Theory]
[InlineData("foolibxamarinbar", false)]
[InlineData("/data/Containers/Bundle/Application/Example.app/libxamarin-dotnet-release.dylib", false)]
[InlineData("/data/libxamarin/something-else.dylib ", true)]
public void ConfigureAppFrame_WithDefaultOptions_ExcludesXamarinFrames(string package, bool expectedInApp)
{
var options = new SentryOptions();
var sut = new SentryStackFrame
{
Function = "async void MainActivity.OnCreate(Bundle savedInstanceState)+(?) =\\u003E { }",
Package = package
};

// Act
sut.ConfigureAppFrame(options);

// Assert
Assert.Equal(expectedInApp, sut.InApp);
}

[Fact]
public void ConfigureAppFrame_WithDefaultOptions_JavaPackageNotInApp()
{
Expand Down
Loading