Skip to content

simplicity-ag/NewRelic

 
 

Repository files navigation

NewRelic module for ZF2

NewRelic module provide an object-oriented PHP wrapper for New Relic monitoring service.

Build Status Latest Stable Version Coverage Status Scrutinizer Quality Score Dependencies Status

Introduction

NewRelic module provide a logger and a wrapper for New Relic PHP API.

The current route is used to set the name of each transaction. Moreover, the module allow exceptions logging if enabled.

Requirements

  • PHP 5.3 or higher

Installation

NewRelic module only officially supports installation through Composer. For Composer documentation, please refer to getcomposer.org.

You can install the module from command line:

$ php composer.phar require neeckeloo/newrelic:1.4.*

Alternatively, you can also add manually the dependency in your composer.json file:

{
    "require": {
        "neeckeloo/newrelic": "1.4.*"
    }
}

Enable the module by adding NewRelic key to your application.config.php file. Customize the module by copy-pasting the newrelic.global.php.dist file to your config/autoload folder.

Default configuration

return array(
    'newrelic' => array(
        // Sets the newrelic app name.  Note that this will discard metrics
        // collected before the name is set.  If empty then your php.ini
        // configuration will take precedence.
        'application_name' => null,

        // May be null and will only be set if application name is also given.
        'license' => null,

        // If false then neither change the auto_instrument or manually
        // instrument the real user monitoring.
        'browser_timing_enabled' => false,

        // When true tell the newrelic extension to insert Real User Monitoring
        // scripts automatically.
        'browser_timing_auto_instrument' => true,

        // When true, a logger with the newrelic writer will be called for
        // dispatch error events.
        'exceptions_logging_enabled' => false,

        // Defines ignored transactions
        'ignored_transactions' => array(),

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

Usage

Ignore transactions

NewRelic API allows to ignore some transactions. This configuration defines some routes and controllers of transactions that will be ignored.

Ignore routes

return array(
    'newrelic' => array(
        'ignored_transactions' => array(
            'routes' => array(
                'admin*',
                'user/login',
            ),
        ),
    ),
);

Those rules ignore all admin routes and the "user/login" route.

Ignore controllers

return array(
    'newrelic' => array(
        'ignored_transactions' => array(
            'controllers' => array(
                'FooController',
                'BarController',
                'BazController',
            ),
        ),
    ),
);

You can also ignore some actions of specified controllers :

return array(
    'newrelic' => array(
        'ignored_transactions' => array(
            'controllers' => array(
                array('FooController', array('foo', 'bar')),
                array('BarController', array('baz')),
            ),
        ),
    ),
);

Ignore a transaction manually

You can ignore a transaction manually by calling ignoreTransaction() method of NewRelic client.

$client = $this->getServiceLocator()->get('NewRelic\Client');
$client->ignoreTransaction();

Define background jobs

The configuration of background jobs is identical to ignored transactions but use the key background_jobs as below.

return array(
    'newrelic' => array(
        'background_jobs' => array(),
    ),
);

Define a background job manually

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

$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.

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

Ignore apdex metrics manually

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

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

Add custom metric

$client = $this->getServiceLocator()->get('NewRelic\Client');
$client->addCustomMetric('salesprice', $price);

About

NewRelic module for Zend Framework 2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%