Skip to content

Commit

Permalink
Ignoring apdex metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
neeckeloo committed Jan 24, 2014
1 parent a22dad0 commit 72d5fc4
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 24 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,36 @@ return array(
);
```

#### Defines a background job manually
#### Define a background job manually

You can define a transaction as background job by calling ```backgroundJob()``` method of NewRelic client.
You can define a transaction as background job manually by calling ```backgroundJob()``` method of NewRelic client.

```php
$client = $this->getServiceLocator()->get('NewRelic\Client');
$client->backgroundJob(true);
```

### Ignore apdex metrics

You can ignore apdex metrics like transaction metrics using the key ```ignored_apdex```.

```php
return array(
'newrelic' => array(
'ignored_apdex' => array(),
),
);
```

#### Ignore apdex metrics manually

You can ignore apdex metrics manually by calling ```ignoreApdex()``` method of NewRelic client.

```php
$client = $this->getServiceLocator()->get('NewRelic\Client');
$client->ignoreApdex(true);
```

### Add custom metric

```php
Expand Down
11 changes: 6 additions & 5 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
'NewRelic\ResponseListener' => 'NewRelic\Listener\ResponseListener',
),
'factories' => array(
'NewRelic\BackgroundJobListener' => 'NewRelic\Service\BackgroundJobListenerFactory',
'NewRelic\ModuleOptions' => 'NewRelic\Service\ModuleOptionsFactory',
'NewRelic\ErrorListener' => 'NewRelic\Service\ErrorListenerFactory',
'NewRelic\Logger' => 'NewRelic\Service\LoggerFactory',
'NewRelic\IgnoredTransactionListener' => 'NewRelic\Service\IgnoredTransactionListenerFactory',
'NewRelic\BackgroundJobListener' => 'NewRelic\Service\BackgroundJobListenerFactory',
'NewRelic\ModuleOptions' => 'NewRelic\Service\ModuleOptionsFactory',
'NewRelic\ErrorListener' => 'NewRelic\Service\ErrorListenerFactory',
'NewRelic\Logger' => 'NewRelic\Service\LoggerFactory',
'NewRelic\IgnoreApdexListener' => 'NewRelic\Service\IgnoreApdexListenerFactory',
'NewRelic\IgnoreTransactionListener' => 'NewRelic\Service\IgnoreTransactionListenerFactory',
),
),
);
7 changes: 6 additions & 1 deletion config/newrelic.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ return array(
// 'exceptions_logging_enabled' => false,

/**
* Defines ignored transactions
* Defines transactions that does not generate metrics
*/
'ignored_transactions' => array(),

/**
* Defines background job transactions
*/
'background_jobs' => array(),

/**
* Defines transactions that does not generate apdex metrics
*/
'ignored_apdex' => array(),
),
);
30 changes: 30 additions & 0 deletions src/NewRelic/Listener/IgnoreApdexListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace NewRelic\Listener;

use Zend\EventManager\EventManagerInterface as Events;
use Zend\Mvc\MvcEvent;

class IgnoreApdexListener extends AbstractTransactionListener
{
/**
* @param Events $events
* @return void
*/
public function attach(Events $events)
{
$this->listeners[] = $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRequest'), -99);
}

/**
* @param MvcEvent $e
* @return void
*/
public function onRequest(MvcEvent $e)
{
if (!$this->isMatchedRequest($e)) {
return;
}

$this->client->ignoreApdex();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Zend\EventManager\EventManagerInterface as Events;
use Zend\Mvc\MvcEvent;

class IgnoredTransactionListener extends AbstractTransactionListener
class IgnoreTransactionListener extends AbstractTransactionListener
{
/**
* @param Events $events
Expand Down
5 changes: 3 additions & 2 deletions src/NewRelic/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Module implements
protected $listeners = array(
'NewRelic\BackgroundJobListener',
'NewRelic\ErrorListener',
'NewRelic\IgnoredTransactionListener',
'NewRelic\IgnoreApdexListener',
'NewRelic\IgnoreTransactionListener',
'NewRelic\RequestListener',
'NewRelic\ResponseListener',
);
Expand Down Expand Up @@ -48,7 +49,7 @@ public function getServiceConfig()
$service->setClient($client);
}
},
'options' => function($service, $sm) {
'module_options' => function($service, $sm) {
if ($service instanceof ModuleOptionsAwareInterface) {
$moduleOptions = $sm->get('NewRelic\ModuleOptions');
$service->setModuleOptions($moduleOptions);
Expand Down
21 changes: 21 additions & 0 deletions src/NewRelic/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class ModuleOptions extends AbstractOptions implements ModuleOptionsInterface
*/
protected $backgroundJobs = array();

/**
* @var array
*/
protected $ignoredApdex = array();

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -161,4 +166,20 @@ public function getBackgroundJobs()
{
return $this->backgroundJobs;
}

/**
* {@inheritdoc}
*/
public function setIgnoredApdex(array $transactions)
{
$this->ignoredApdex = $transactions;
}

/**
* {@inheritdoc}
*/
public function getIgnoredApdex()
{
return $this->ignoredApdex;
}
}
11 changes: 11 additions & 0 deletions src/NewRelic/ModuleOptionsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ public function setBackgroundJobs(array $transactions);
* @return array
*/
public function getBackgroundJobs();

/**
* @param array $transactions
* @return self
*/
public function setIgnoredApdex(array $transactions);

/**
* @return array
*/
public function getIgnoredApdex();
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php
namespace NewRelic\Service;

use NewRelic\Listener\IgnoredTransactionListener;
use NewRelic\Listener\IgnoreApdexListener;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* NewRelic ignored transaction listener factory
* NewRelic ignore apdex listener factory
*/
class IgnoredTransactionListenerFactory implements FactoryInterface
class IgnoreApdexListenerFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return IgnoredTransactionListener
* @return IgnoreApdexListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$moduleOptions = $serviceLocator->get('NewRelic\ModuleOptions');

return new IgnoredTransactionListener($moduleOptions->getIgnoredTransactions());
return new IgnoreApdexListener($moduleOptions->getIgnoredApdex());
}
}
23 changes: 23 additions & 0 deletions src/NewRelic/Service/IgnoreTransactionListenerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace NewRelic\Service;

use NewRelic\Listener\IgnoreTransactionListener;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* NewRelic ignore transaction listener factory
*/
class IgnoreTransactionListenerFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return IgnoreTransactionListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$moduleOptions = $serviceLocator->get('NewRelic\ModuleOptions');

return new IgnoreTransactionListener($moduleOptions->getIgnoredTransactions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use NewRelic\ClientInterface;
use Zend\Mvc\MvcEvent;

class IgnoredTransactionListenerTest extends \PHPUnit_Framework_TestCase
class IgnoreTransactionListenerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ClientInterface
Expand Down Expand Up @@ -40,7 +40,7 @@ public function setUp()
*/
protected function getListener($transactions)
{
$listener = new IgnoredTransactionListener($transactions);
$listener = new IgnoreTransactionListener($transactions);
$listener->setClient($this->client);

return $listener;
Expand Down
37 changes: 37 additions & 0 deletions tests/NewRelic/Service/IgnoreApdexListenerFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace NewRelic\Service;

class IgnoreApdexListenerFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var IgnoreApdexListenerFactory
*/
protected $ignoreApdexListenerFactory;

public function setUp()
{
$this->ignoreApdexListenerFactory = new IgnoreApdexListenerFactory();
}

public function testCreateService()
{
$moduleOptions = $this->getMock('NewRelic\ModuleOptions');
$moduleOptions
->expects($this->once())
->method('getIgnoredApdex')
->will($this->returnValue(array()));

$serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceManager')
->disableOriginalConstructor()
->setMethods(array('get'))
->getMock();

$serviceManager->expects($this->once())
->method('get')
->will($this->returnValue($moduleOptions));

$listener = $this->ignoreApdexListenerFactory->createService($serviceManager);

$this->assertInstanceOf('NewRelic\Listener\IgnoreApdexListener', $listener);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
namespace NewRelic\Service;

class IgnoredTransactionListenerFactoryTest extends \PHPUnit_Framework_TestCase
class IgnoreTransactionListenerFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var IgnoredTransactionListenerFactory
* @var IgnoreTransactionListenerFactory
*/
protected $ignoredTransactionListenerFactory;
protected $ignoreTransactionListenerFactory;

public function setUp()
{
$this->ignoredTransactionListenerFactory = new IgnoredTransactionListenerFactory();
$this->ignoreTransactionListenerFactory = new IgnoreTransactionListenerFactory();
}

public function testCreateService()
Expand All @@ -30,8 +30,8 @@ public function testCreateService()
->method('get')
->will($this->returnValue($moduleOptions));

$listener = $this->ignoredTransactionListenerFactory->createService($serviceManager);
$listener = $this->ignoreTransactionListenerFactory->createService($serviceManager);

$this->assertInstanceOf('NewRelic\Listener\IgnoredTransactionListener', $listener);
$this->assertInstanceOf('NewRelic\Listener\IgnoreTransactionListener', $listener);
}
}

0 comments on commit 72d5fc4

Please sign in to comment.