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

Simplify breadcrumb API #1603

Merged
merged 4 commits into from
Oct 30, 2023
Merged

Simplify breadcrumb API #1603

merged 4 commits into from
Oct 30, 2023

Conversation

stayallive
Copy link
Collaborator

@stayallive stayallive commented Oct 24, 2023

Currently the breadcrumb creation looks something like this:

\Sentry\addBreadcrumb(
    new \Sentry\Breadcrumb(
        \Sentry\Breadcrumb::LEVEL_INFO,
        \Sentry\Breadcrumb::TYPE_DEFAULT,
        'auth',                // category
        'User authenticated',  // message (optional)
        ['user_id' => $userId] // data (optional)
    )
);

I would like to be able to write this shorter, something like:

\Sentry\addBreadcrumb('auth', 'User authenticated', ['user_id' => $userId]);

// or with PHP 8:
\Sentry\addBreadcrumb(
    category: 'auth', 
    message: 'User authenticated',
    metadata: ['user_id' => $userId],
);

This removed the need for creating new objects and setting the level and type so you only have to pass in a category (could maybe also be defaulted) and a message and optional metadata.

It was also suggested to have a global sentry() function (not namespaced) so it could be just sentry()->addBreadcrumb(...) but not sure if we want to go that far.

This is more of a discussion PR, curious to hear your thoughts! My main goal is to be able to add context and leave breadcrumbs as short and easy as possible to have users do it more and more easily.

@cleptric
Copy link
Member

No objections. I do like that we don't break for existing users, and the new way of adding breadcrumbs seems much easier, which is great.

@cleptric cleptric changed the title [4.x] Simplify breadcrumb API Simplify breadcrumb API Oct 25, 2023
@cleptric cleptric added this to the 4.0 milestone Oct 25, 2023
@cleptric cleptric merged commit fc5853f into 4.x Oct 30, 2023
31 checks passed
@cleptric cleptric deleted the simplify-breadcrumb-api branch October 30, 2023 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants