PHP, Web Development, Yii Framework

Stop Newrelic from recording slow AJAX/general calls in Yii2

I recently had to stop Newrelic from recording my long polling tactics so I came up with:

<?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