-
-
Notifications
You must be signed in to change notification settings - Fork 220
MAUI events become extra context in Sentry events #1706
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b873f55
Continue with adding MAUI support
mattjohnsonpint 061f9bb
Update CHANGELOG.md
mattjohnsonpint 7f2c921
Add workaround for iOS unhandled exception
mattjohnsonpint 6a2aa6b
Typo
mattjohnsonpint 5d14004
Update CHANGELOG.md
mattjohnsonpint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -8,6 +8,8 @@ public static MauiApp CreateMauiApp() => | |
.UseSentry(options => | ||
{ | ||
options.Dsn = "https://[email protected]/5428537"; | ||
options.Debug = true; | ||
options.MaxBreadcrumbs = int.MaxValue; // TODO: reduce breadcrumbs, remove this | ||
}) | ||
.ConfigureFonts(fonts => | ||
{ | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 ? | ||
mattjohnsonpint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data.Add(prefix + nameof(textElement.Text), textElement.Text); | ||
} | ||
} | ||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.