-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAUI events become extra context in Sentry events (#1706)
- Loading branch information
1 parent
89cad6d
commit bbf2f4a
Showing
20 changed files
with
636 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Sentry.Maui/Constants.cs → src/Sentry.Maui/Internal/Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Sentry.Maui.Internal; | ||
|
||
// This is a helper we register as a singleton on the service provider. | ||
// It allows us to register other items that should be disposed when the service provider disposes. | ||
// TODO: There might be something like this built-in to .NET already. Investigate and replace if so. | ||
|
||
internal class Disposer : IDisposable | ||
{ | ||
private readonly List<IDisposable> _disposables = new(); | ||
|
||
public void Register(IDisposable disposable) | ||
{ | ||
_disposables.Add(disposable); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
foreach (var disposable in _disposables) | ||
{ | ||
disposable.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
namespace Sentry.Maui.Internal; | ||
|
||
internal static class Extensions | ||
{ | ||
public static void AddBreadcrumbForEvent(this IHub hub, | ||
object? sender, | ||
string eventName, | ||
string? type, | ||
string? category, | ||
Action<Dictionary<string, string>>? addExtraData) | ||
=> hub.AddBreadcrumbForEvent(sender, eventName, type, category, default, addExtraData); | ||
|
||
public static void AddBreadcrumbForEvent(this IHub hub, | ||
object? sender, | ||
string eventName, | ||
string? type = null, | ||
string? category = null, | ||
BreadcrumbLevel level = default, | ||
Action<Dictionary<string, string>>? addExtraData = null) | ||
{ | ||
var data = new Dictionary<string, string>(); | ||
if (sender is Element element) | ||
{ | ||
data.AddElementInfo(element, null); | ||
} | ||
|
||
addExtraData?.Invoke(data); | ||
|
||
var message = sender != null ? $"{sender.GetType().Name}.{eventName}" : eventName; | ||
hub.AddBreadcrumb(message, category, type, data, level); | ||
} | ||
|
||
public static void AddElementInfo(this IDictionary<string, string> data, Element? element, string? property) | ||
{ | ||
if (element is null) | ||
{ | ||
return; | ||
} | ||
|
||
var typeName = element.GetType().Name; | ||
var prefix = (property ?? typeName) + "."; | ||
|
||
if (property != null) | ||
{ | ||
data.Add(property, typeName); | ||
} | ||
|
||
// The element ID seems to be mostly useless noise | ||
//data.Add(prefix + nameof(element.Id), element.Id.ToString()); | ||
|
||
if (element.StyleId != null) | ||
{ | ||
// The StyleId correlates to the element's name if one is set in XAML | ||
// TODO: Is there a better way to get this? | ||
data.Add(prefix + "Name", element.StyleId); | ||
} | ||
|
||
if (element is ITitledElement { Title: { } } titledElement) | ||
{ | ||
// TODO: Scrub PII ? | ||
data.Add(prefix + nameof(titledElement.Title), titledElement.Title); | ||
} | ||
|
||
if (element is IText { Text: { } } textElement) | ||
{ | ||
// TODO: Scrub PII ? | ||
data.Add(prefix + nameof(textElement.Text), textElement.Text); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Sentry.Maui.Internal; | ||
|
||
internal interface IMauiEventsBinder | ||
{ | ||
void BindMauiEvents(); | ||
} |
Oops, something went wrong.