Skip to content

Add element binding extensibility#3997

Merged
aritchie merged 6 commits intomainfrom
3996-maui_element_extensibility
Feb 25, 2025
Merged

Add element binding extensibility#3997
aritchie merged 6 commits intomainfrom
3996-maui_element_extensibility

Conversation

@aritchie
Copy link
Copy Markdown
Contributor

Implements #3996

@aritchie aritchie marked this pull request as draft February 24, 2025 20:01
Comment thread src/Sentry.Maui/Internal/MauiEventsBinder.cs
@aritchie aritchie marked this pull request as ready for review February 25, 2025 18:47
Copy link
Copy Markdown
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

About the only thing I couldn't see (maybe I missed it) is where MauiButtonEventsBinder gets tested. I see tests for MauiImageButtonEventsBinder.

If these are missing, would be good to add them before merge.

@aritchie
Copy link
Copy Markdown
Contributor Author

ImageButton tests are under MauiEventsBinder.ImageButton.

@aritchie aritchie merged commit fbdcce9 into main Feb 25, 2025
@aritchie aritchie deleted the 3996-maui_element_extensibility branch February 25, 2025 23:18
@jamescrosswell
Copy link
Copy Markdown
Collaborator

ImageButton tests are under MauiEventsBinder.ImageButton.

Yeah I saw those. I didn't see any equivalent for MauiButtonEventsBinder though...

@aritchie
Copy link
Copy Markdown
Contributor Author

They already existed. I only moved button code out of the original mauieventbinder into its own element binder

@jamescrosswell
Copy link
Copy Markdown
Collaborator

They already existed. I only moved button code out of the original mauieventbinder into its own element binder

Do you know where they are? Rider couldn't find any references to MauiButtonEventsBinder for me...

@aritchie
Copy link
Copy Markdown
Contributor Author

Sentry.Maui/Internals/MauiButtonEventsBinder & Sentry.Maui/Internals/MauiImageButtonEventsBinder

@jamescrosswell
Copy link
Copy Markdown
Collaborator

Sentry.Maui/Internals/MauiButtonEventsBinder & Sentry.Maui/Internals/MauiImageButtonEventsBinder

Yeah I saw the classes... I didn't see the tests. I think this is them though:

[Theory]
[InlineData(nameof(Button.Clicked))]
[InlineData(nameof(Button.Pressed))]
[InlineData(nameof(Button.Released))]
public void Button_CommonEvents_AddsBreadcrumb(string eventName)
{
// Arrange
var button = new Button
{
StyleId = "button"
};
var el = new ElementEventArgs(button);
_fixture.Binder.OnApplicationOnDescendantAdded(null, el);
// Act
button.RaiseEvent(eventName, EventArgs.Empty);
// Assert
var crumb = Assert.Single(_fixture.Scope.Breadcrumbs);
Assert.Equal($"{nameof(Button)}.{eventName}", crumb.Message);
Assert.Equal(BreadcrumbLevel.Info, crumb.Level);
Assert.Equal(MauiEventsBinder.UserType, crumb.Type);
Assert.Equal(MauiEventsBinder.UserActionCategory, crumb.Category);
crumb.Data.Should().Contain($"{nameof(Button)}.Name", "button");
}

@jamescrosswell jamescrosswell linked an issue Mar 3, 2025 that may be closed by this pull request
_hub.AddBreadcrumbForEvent(
_options,
breadcrumb.Sender,
breadcrumb.EventName,
Copy link
Copy Markdown
Contributor

@albyrock87 albyrock87 Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamescrosswell I'm sorry for this late review but I just realized there's a huge bug here.

What about breadcrumb.ExtraData? I think you completely missed it.

Also I don't find the ExtraData type very convenient.

I think that this could be more convenient:

public record BreadcrumbEvent(
    object? Sender,
    string EventName,
    params (string Key, string Value)[] ExtraData
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal void OnBreadcrumbCreateCallback(BreadcrumbEvent breadcrumb)
    {
        void AddExtraData(Dictionary<string, string> extraData)
        {
            foreach (var data in breadcrumb.ExtraData.SelectMany(d => d))
            {
                extraData[data.Key] = data.Value;
            }
        }

        _hub.AddBreadcrumbForEvent(
            _options,
            breadcrumb.Sender,
            breadcrumb.EventName,
            UserType,
            UserActionCategory,
            AddExtraData
        );
    }

Copy link
Copy Markdown
Collaborator

@jamescrosswell jamescrosswell Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve MAUI user-events observability (breadcrumbs)

3 participants