bugsnag / bugsnag-symfony

BugSnag notifier for the Symfony PHP framework. Monitor and report errors in your Symfony apps.
https://docs.bugsnag.com/platforms/php/symfony
MIT License
43 stars 21 forks source link

Add meta data aware interface and trait #83

Closed migo315 closed 4 years ago

migo315 commented 4 years ago

Goal

Provide a very simple way to extend an exception with additional meta data everywhere without further dependencies.

Design

This feature is very pragmatic and straightforward. Similar to PSR Logger, we provide a MetaDataAwareInterface and a MetaDataAwareTrait. The developer can (but must not) extend his Exceptions with the Interface / Trait to add some additional informations:

class UnrecoverableProcessException extends Exception implements MetaDataAwareInterface
{
    use MetaDataAwareTrait;
}

Later just pass your informations:

$exception = new UnrecoverableProcessException('I am an Exception');
$exception->addMetaData(['myTab' => [
    'foo' => 'bar',
]]);

throw $exception;

This implementation does not need any services or heavy structures.

Changeset

Added

Changed

Tests

I have added automatic tests (with and without meta data)

Review

For the submitter, initial self-review:

For the pull request reviewer(s), this changeset has been reviewed for:

mattdyoung commented 4 years ago

Hi @migo315

Thanks for the PR. We plan to look into this and consider whether we want to use this approach across our PHP integrations.

migo315 commented 4 years ago

I can split this this if you like. Interface and Trait to bugsnag-php. Then all additional php libraries can use the Interface and Trait (Symfony, Laravel etc).

mattdyoung commented 4 years ago

@migo315 That sounds really useful if you have the time. To be clear, with our current priorities it will be at least a few weeks until we're able to have a detailed look at your PR and there would be work on our side to document this and ensure we're happy with the interface and test coverage. So in the short term you may want to fork the repository to make use of your own changes, but we do like the approach so are likely to take this on once we have the bandwidth.

Also, a word of caution. We currently support PHP 5.2+ and I believe Traits only came in 5.4, so we'd need to ensure we consider the best way to handle that.

migo315 commented 4 years ago

I've created an PR for your PHP SDK https://github.com/bugsnag/bugsnag-php/pull/574

johnkiely1 commented 4 years ago

This has now been fixed via php release V3.21.0 https://github.com/bugsnag/bugsnag-php/releases/tag/v3.21.0. running composer update bugsnag/bugsnag will pull in latest version

We have added support for the getting the original error on which you can attach additional metadata.