Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose IsSystemModuleName as a public static function. #1493

Merged
merged 4 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions src/Sentry/Exceptions/SentryStackFrame.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
Expand Down Expand Up @@ -160,6 +161,27 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
writer.WriteEndObject();
}

/// <summary>
/// Configures <see cref="InApp"/> based on the InApp defined on SentryOptions.
/// </summary>
/// <param name="options">The Sentry options.</param>
/// <remarks><see cref="InApp"/> will remain with the same value if previously set.</remarks>
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;
}
}

lucas-zimerman marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Parses from JSON.
/// </summary>
Expand Down
13 changes: 1 addition & 12 deletions src/Sentry/Extensibility/SentryStackTraceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool deman
}
}

frame.InApp ??= !IsSystemModuleName(frame.Module);
frame.ConfigureAppFrame(_options);

frame.FileName = stackFrame.GetFileName();

Expand Down Expand Up @@ -211,17 +211,6 @@ protected SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool deman
protected virtual MethodBase? GetMethod(StackFrame stackFrame)
=> stackFrame.GetMethod();

private bool IsSystemModuleName(string? moduleName)
{
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;
}

/// <summary>
/// Clean up function and module names produced from `async` state machine calls.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ namespace Sentry
public System.Collections.Generic.IList<string> PreContext { get; }
public long? SymbolAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> 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) { }
}
Expand Down
68 changes: 68 additions & 0 deletions test/Sentry.Tests/Protocol/Exceptions/SentryStackFrameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}