bugsnag / bugsnag-wordpress

BugSnag error monitoring for WordPress sites
http://wordpress.org/plugins/bugsnag/
GNU General Public License v2.0
20 stars 15 forks source link

$bugsnagWordpress->setNotifyReleaseStages doesn't work #33

Closed jorenvh closed 4 years ago

jorenvh commented 6 years ago

Expected behavior

$bugsnagWordpress->setNotifyReleaseStages(['production']); Should only report errors from production env

Observed behavior

Reports errors from all env

Steps to reproduce

Version

1.3.1

Additional information

In Configuration.php in the method shouldNotify is $this->notifyReleaseStages = NULL, setNotifyReleaseStages in Client.php is never triggered for what I was able to debug.

https://docs.bugsnag.com/platforms/php/wordpress/configuration-options/#setnotifyreleasestages

Also added on the Wordpress support forum: https://wordpress.org/support/topic/bugsnagwordpress-setnotifyreleasestages-doesnt-work/

aglipanci commented 5 years ago

Any update on this? I think it's the same thing with setBeforeNotifyFunction.

Having $bugsnagWordpress as global can be a solution. Or having a filter or action inside constructBugsnag to pass the client that we can add more information on the way.

tillkruss commented 5 years ago

You can use a MU plugin:

add_action('plugins_loaded', function () {
    global $bugsnagWordpress;

    if (method_exists($bugsnagWordpress, 'setNotifyReleaseStages')) {
        $bugsnagWordpress->setNotifyReleaseStages(['staging', 'production']);
    }
});
Cawllec commented 5 years ago

Hi @jorenvh, sorry it's taken so long to get to your issue. Upon investigating the behaviour seems to be working as expected.

Adding the following lines to themes/{theme}/functions.php:

$bugsnagWordpress->setNotifyReleaseStages(['production', 'foo', 'bar']);
$bugsnagWordpress->setReleaseStage('development');

Will not notify any exceptions that occur. Likewise, through debugging, the value for NotifyReleaseStages was reported as Array ( [0] => production [1] => foo [2] => bar ).

Are you sure you're setting your apps ReleaseStage, as described in the docs?

Cawllec commented 5 years ago

I'm closing this issue for now, however if this reoccurs or you have any further issues please get in touch.

jorenvh commented 5 years ago

Hi @Cawllec

Thank you for getting back to me. I will check this first thing in the morning I might be missing something in my code.

Kr Joren

jorenvh commented 5 years ago

@Cawllec Upon further investigation this isn't working

I added the following to my themes functions.php file:

$bugsnagWordpress->setReleaseStage(WP_ENV);
$bugsnagWordpress->setNotifyReleaseStages(['production', 'staging']);

Also tried reversing them:

$bugsnagWordpress->setNotifyReleaseStages(['production', 'staging']);
$bugsnagWordpress->setReleaseStage(WP_ENV);

If I dump the $bugsnagWordpress variable/object I can see that my release stages are set properly. However when in the shouldNotifymethod of the bugsnag/bugsnag-php/Configuration.phpfile I'm getting NULL

WP_ENV in the examples above = development

When forcing an error by for example removing a ; somewhere in the code base, Busnag is still notified about this. Development however is not set as a release stage

imjoehaines commented 4 years ago

Hi @jorenvh, I've been looking into this and I think this is due to PHP behaviour, so isn't something we can fix

If you have a syntax error in the same file as the Bugsnag configuration then PHP doesn't to call the setters, so the release stage configuration is ignored. For example, adding the following to your functions.php file will report the syntax error to Bugsnag:

$bugsnagWordpress->setReleaseStage('foo');
$bugsnagWordpress->setNotifyReleaseStages(['bar']);

'this is a syntax error'

However, if you split the Bugsnag configuration and the code that generates the syntax error into separate files, PHP will correctly call Bugsnag's setters and therefore the release stage configuration will work as expected:

// functions.php
require_once __DIR__ . '/bugsnag.php';
require_once __DIR__ . '/syntax-error.php';

// bugsnag.php
$bugsnagWordpress->setReleaseStage('foo');
$bugsnagWordpress->setNotifyReleaseStages(['bar']);

// syntax-error.php
'this is a syntax error'

I don't think we're able to work around this as it's caused by how PHP executes the code when it encounters a file with a syntax error