PHP, Web Development, Yii Framework

Stop Newrelic From Recording Slow AJAX/General Calls in Yii2

<?php

namespace common\components;

use Yii;
use yii\base\Component;
use yii\base\BootstrapInterface;
use yii\web\Application;
use yii\web\Controller;

class Newrelic extends Component implements BootstrapInterface
{
    public $ignoreRoutes = [];

    public function bootstrap($app)
    {
        // delay attaching event handler to the view component after it is fully configured
        $app->on(Controller::EVENT_BEFORE_ACTION, function () use ($app) {
            $this->beforeAction($app);
        });
    }

    public function beforeAction($app)
    {
        if (extension_loaded('newrelic')) {
            if (in_array(Yii::$app->getUrlManager()->parseRequest($app->request)[0], $this->ignoreRoutes)) {
                newrelic_ignore_transaction();
            }
        }
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s