-
-
Notifications
You must be signed in to change notification settings - Fork 225
fix: ExtraData not captured for Breadcrumbs in MauiEventsBinder #4254
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
Changes from all commits
94ee8f6
97cf6bb
ddfcd8b
5a38114
0258492
ad5a8d5
c79fa03
f5f0ad2
f4f14f9
89e72e8
a264395
dbf9985
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| namespace Sentry.Maui; | ||
|
|
||
| /// <summary> | ||
| /// Argument to the OnBreadcrumbCreateCallback | ||
| /// </summary> | ||
| public sealed class BreadcrumbEvent | ||
| { | ||
| /// <summary> | ||
| /// The sender of the event, usually the control that triggered it. | ||
| /// </summary> | ||
| public object? Sender { get; } | ||
|
|
||
| /// <summary> | ||
| /// The event name (e.g. "Tapped", "Swiped", etc.) | ||
| /// </summary> | ||
| public string EventName { get; } | ||
|
|
||
| /// <summary> | ||
| /// Any extra data to be included in the breadcrumb. This would typically be event specific information (for example | ||
| /// it could include the X, Y coordinates of a tap event). | ||
| /// </summary> | ||
| public IEnumerable<KeyValuePair<string, string>> ExtraData { get; } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new BreadcrumbEvent | ||
| /// </summary> | ||
| public BreadcrumbEvent(object? sender, string eventName) | ||
| : this(sender, eventName, Array.Empty<KeyValuePair<string, string>>()) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new BreadcrumbEvent | ||
| /// </summary> | ||
| public BreadcrumbEvent( | ||
| object? sender, | ||
| string eventName, | ||
| params IEnumerable<KeyValuePair<string, string>> extraData) | ||
| { | ||
| Sender = sender; | ||
| EventName = eventName; | ||
| ExtraData = extraData; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new BreadcrumbEvent | ||
| /// </summary> | ||
| public BreadcrumbEvent( | ||
| object? sender, | ||
| string eventName, | ||
| params IEnumerable<(string key, string value)> extraData) : this(sender, eventName, extraData.Select( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. final comment: deferred execution The On the other hand, since we accept On second thought ... I believe this is great as it is. |
||
| e => new KeyValuePair<string, string>(e.key, e.value))) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This constructor remains for backward compatibility. | ||
| /// </summary> | ||
| /// <param name="sender"></param> | ||
| /// <param name="eventName"></param> | ||
| /// <param name="extraData"></param> | ||
| [Obsolete("Use one of the other simpler constructors instead.")] | ||
| public BreadcrumbEvent( | ||
| object? sender, | ||
| string eventName, | ||
| IEnumerable<(string Key, string Value)>[] extraData) : this(sender, eventName, extraData.SelectMany( | ||
| x => x.Select(pair => new KeyValuePair<string, string>(pair.Key, pair.Value))) | ||
| ) | ||
| { | ||
| } | ||
| } | ||
Flash0ver marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using System.Collections.Generic; | ||
| using FluentAssertions; | ||
| using Xunit; | ||
|
|
||
| namespace Sentry.Maui.Tests; | ||
|
|
||
| public class BreadcrumbEventTests | ||
| { | ||
| [Fact] | ||
| public void BreadcrumbEvent_OldConstructor_EquivalentToNewConstructor() | ||
| { | ||
| // Arrange | ||
| var sender = new object(); | ||
| var eventName = "TestEvent"; | ||
|
|
||
| // Act | ||
| IEnumerable<(string Key, string Value)>[] extraData = [[("key1", "value1")], [("key2", "value2")]]; | ||
| #pragma warning disable CS0618 // Type or member is obsolete | ||
| var oldEvent = new BreadcrumbEvent(sender, eventName, extraData); | ||
| #pragma warning restore CS0618 // Type or member is obsolete | ||
| var newEvent = new BreadcrumbEvent(sender, eventName, ("key1", "value1"), ("key2", "value2")); | ||
|
|
||
| // Assert | ||
| oldEvent.Sender.Should().Be(newEvent.Sender); | ||
| oldEvent.EventName.Should().Be(newEvent.EventName); | ||
| oldEvent.ExtraData.Should().BeEquivalentTo(newEvent.ExtraData); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using Sentry.Maui.Internal; | ||
|
|
||
| namespace Sentry.Maui.Tests; | ||
|
|
||
| internal class MauiEventsBinderFixture | ||
| { | ||
| public IHub Hub { get; } | ||
|
|
||
| public MauiEventsBinder Binder { get; } | ||
|
|
||
| public Scope Scope { get; } = new(); | ||
|
|
||
| public SentryMauiOptions Options { get; } = new(); | ||
|
|
||
| public MauiEventsBinderFixture(params IEnumerable<IMauiElementEventBinder> elementEventBinders) | ||
| { | ||
| Hub = Substitute.For<IHub>(); | ||
| Hub.SubstituteConfigureScope(Scope); | ||
|
|
||
| Scope.Transaction = Substitute.For<ITransactionTracer>(); | ||
|
|
||
| Options.Debug = true; | ||
| var logger = Substitute.For<IDiagnosticLogger>(); | ||
| logger.IsEnabled(Arg.Any<SentryLevel>()).Returns(true); | ||
| Options.DiagnosticLogger = logger; | ||
| var options = Microsoft.Extensions.Options.Options.Create(Options); | ||
| Binder = new MauiEventsBinder( | ||
| Hub, | ||
| options, | ||
| elementEventBinders | ||
| ); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.