Skip to content

Commit 2cae234

Browse files
authored
Merge pull request #171 from getsentry/feature/in-app-include
feat: InAppInclude
2 parents 3dbcba4 + 6253564 commit 2cae234

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed

samples/Sentry.Samples.Console.Customized/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ await SentrySdk.ConfigureScopeAsync(async scope =>
4343
// To see the lines from non `AppCode`, select `Full`. That'll include non App code like System.*, Microsoft.* and LibraryX.*
4444
o.AddInAppExclude("LibraryX.");
4545

46+
// Before excluding all prefixed 'LibraryX.', any stack trace from a type namespaced 'LibraryX.Core' will be considered InApp.
47+
o.AddInAppInclude("LibraryX.Core");
48+
4649
// Send personal identifiable information like the username logged on to the computer and machine name
4750
o.SendDefaultPii = true;
4851

src/Sentry/Internal/SentryStackTraceFactory.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ private bool IsSystemModuleName(string moduleName)
134134
return false;
135135
}
136136

137+
foreach (var include in _options.InAppInclude)
138+
{
139+
if (moduleName.StartsWith(include, StringComparison.Ordinal))
140+
{
141+
return false;
142+
}
143+
}
144+
137145
foreach (var exclude in _options.InAppExclude)
138146
{
139147
if (moduleName.StartsWith(exclude, StringComparison.Ordinal))

src/Sentry/SentryOptions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ public class SentryOptions : IScopeOptions
6565
/// </example>
6666
internal ImmutableList<string> InAppExclude { get; set; }
6767

68+
/// <summary>
69+
/// A list of namespaces (or prefixes) considered part of application code
70+
/// </summary>
71+
/// <remarks>
72+
/// Sentry by default filters the stacktrace to display only application code.
73+
/// A user can optionally click to see all which will include framework and libraries.
74+
/// A <see cref="string.StartsWith(string)"/> is executed
75+
/// </remarks>
76+
/// <example>
77+
/// 'System.CustomNamespace', 'Microsoft.Azure.App'
78+
/// </example>
79+
/// <seealso href="https://docs.sentry.io/error-reporting/configuration/?platform=csharp#in-app-include"/>
80+
internal ImmutableList<string> InAppInclude { get; set; }
81+
6882
/// <summary>
6983
/// Whether to include default Personal Identifiable information
7084
/// </summary>
@@ -328,6 +342,8 @@ public SentryOptions()
328342
"FSharp.",
329343
"Serilog",
330344
"Giraffe.");
345+
346+
InAppInclude = ImmutableList<string>.Empty;
331347
}
332348
}
333349
}

src/Sentry/SentryOptionsExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ public static void AddIntegration(this SentryOptions options, ISdkIntegration in
4848
public static void AddInAppExclude(this SentryOptions options, string prefix)
4949
=> options.InAppExclude = options.InAppExclude.Add(prefix);
5050

51+
/// <summary>
52+
/// Add prefix to include as in 'InApp' stack trace.
53+
/// </summary>
54+
/// <param name="options"></param>
55+
/// <param name="prefix"></param>
56+
public static void AddInAppInclude(this SentryOptions options, string prefix)
57+
=> options.InAppInclude = options.InAppInclude.Add(prefix);
58+
5159
/// <summary>
5260
/// Add an exception processor
5361
/// </summary>

test/Sentry.Tests/Internals/SentryStackTraceFactoryTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ public void CreateSentryStackFrame_AppNamespaceExcluded_NotInAppFrame()
9999
Assert.False(actual.InApp);
100100
}
101101

102+
[Fact]
103+
public void CreateSentryStackFrame_NamespaceIncludedAndExcluded_IncludesTakesPrecedence()
104+
{
105+
_fixture.SentryOptions.AddInAppExclude(GetType().Namespace);
106+
_fixture.SentryOptions.AddInAppInclude(GetType().Namespace);
107+
var sut = _fixture.GetSut();
108+
var frame = new StackFrame();
109+
110+
var actual = sut.CreateFrame(frame);
111+
112+
Assert.True(actual.InApp);
113+
}
114+
102115
// https://github.com/getsentry/sentry-dotnet/issues/64
103116
[Fact]
104117
public void DemangleAnonymousFunction_NullFunction_ContinuesNull()

test/Sentry.Tests/SentryOptionsExtensionsTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public void AddInAppExclude_StoredInOptions()
4343
Assert.Contains(Sut.InAppExclude, actual => actual == expected);
4444
}
4545

46+
[Fact]
47+
public void AddInAppInclude_StoredInOptions()
48+
{
49+
const string expected = "test";
50+
Sut.AddInAppInclude(expected);
51+
Assert.Contains(Sut.InAppInclude, actual => actual == expected);
52+
}
53+
4654
[Fact]
4755
public void AddExceptionProcessor_StoredInOptions()
4856
{

0 commit comments

Comments
 (0)