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

Report Handled Exceptions To New Relic #11944

Merged
merged 9 commits into from Nov 10, 2017

Conversation

@mpchadwick
Contributor

mpchadwick commented Nov 2, 2017

Description

Currently, if you're using New Relic you'll know about fatal errors via the APM instrumentation, but handled exceptions will not be reported. This change reports handled exceptions to New Relic

Manual testing scenarios

  1. Configure the New Relic PHP agent in your environment and enable the New Relic module
  2. Purposely enter the wrong database credentials in app/etc/env.php.
  3. Notice the exception being reported to New Relic

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)
@toddbc

This comment has been minimized.

Contributor

toddbc commented Nov 2, 2017

This is a really important change to enable error metrics, alerts, and even correlation within New Relic.

Really looking forward to this support within Magento 2.

@@ -153,6 +153,8 @@ public function launch()
*/
public function catchException(Bootstrap $bootstrap, \Exception $exception)
{
$this->_eventManager->dispatch('application_handled_exception', ['exception' => $exception]);

This comment has been minimized.

@orlangur

orlangur Nov 2, 2017

Contributor

New events must not be created, you can implement this logic as a before plugin for catchException method.

This comment has been minimized.

@mpchadwick

mpchadwick Nov 3, 2017

Contributor

@orlangur i refactored it to use a plugin.

$this->newRelicWrapper = $newRelicWrapper;
}
public function beforeCatchException(Http $subject, $bootstrap, $exception)

This comment has been minimized.

@ihor-sviziev

ihor-sviziev Nov 3, 2017

Contributor

Could you add types for $bootstrap and $exception? Also phpdoc block is missing

This comment has been minimized.

@mpchadwick

mpchadwick Nov 4, 2017

Contributor

@ihor-sviziev this is done.

/**
* @var NewRelicWrapper
*/
protected $newRelicWrapper;

This comment has been minimized.

@ihor-sviziev

ihor-sviziev Nov 4, 2017

Contributor

In general looks good, btw new properties should be private instead of protected. Sorry for missing if prev. time

This comment has been minimized.

@toddbc

toddbc Nov 4, 2017

Contributor

Just wondering - even new properties to new classes? I understand the BC concerns for existing classes (2.2.0 lacking something that 2.1.11 has, etc.), but does it help for new classes too in some way?

This comment has been minimized.

@ihor-sviziev

ihor-sviziev Nov 4, 2017

Contributor

According to technical guidelines: http://devdocs.magento.com/guides/v2.1/coding-standards/technical-guidelines/technical-guidelines.html

2.7. All non-public properties and methods SHOULD be private.

This comment has been minimized.

@mpchadwick

mpchadwick Nov 6, 2017

Contributor

@ihor-sviziev this is done

@vrann vrann self-assigned this Nov 9, 2017

@vrann vrann added this to the November 2017 milestone Nov 9, 2017

@vrann vrann added this to TODO in Community Pull Requests Nov 9, 2017

@magento-team magento-team moved this from TODO to Merging In Progress in Community Pull Requests Nov 9, 2017

@okorshenko okorshenko merged commit 6bc4fcf into magento:2.2-develop Nov 10, 2017

3 checks passed

codacy/pr Good work! A positive pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details

Community Pull Requests automation moved this from Merging In Progress to Done Nov 10, 2017

@iainhubbard

This comment has been minimized.

Contributor

iainhubbard commented Nov 14, 2017

Not done my background research on this but does lib/internal/Magento/Framework/App/Http.php encompass all the entry points into magento e.g. cron, cli, XML API etc. We have always done this change in pub/errors/report.php. Still a core change obviously. e.g.

    $processor->saveReport($reportData);
    if (function_exists('newrelic_notice_error')) {
        if (isset($reportData[1])) {
            if (!isset($e) || $e->getTraceAsString() !== $reportData[1]) {
                newrelic_notice_error($reportData[0] . "\n" . $reportData[1]);
            } else {
                newrelic_notice_error($e->getMessage(), $e);
            }
        } elseif (isset($e)) {
            newrelic_notice_error($e->getMessage(), $e);
        }
    }

Not tested etc etc

This has the benefit of not relying on magento for anything especially in the event of a catastrophic failure.

@ihor-sviziev

This comment has been minimized.

Contributor

ihor-sviziev commented Nov 14, 2017

@iainhubbard if you have any issues with this implementation and know how to improve this module - that's really good! waiting for a PR from you

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