PHP code example of mir-insight / cakephp-newrelic

1. Go to this page and download the library: Download mir-insight/cakephp-newrelic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mir-insight / cakephp-newrelic example snippets


// Load the plugin
$app->addPlugin('NewRelic');

return [
    'NewRelic' => [
        'enabled' => true,
        'appName' => 'My Application',
        'captureParams' => true,
        'customParameters' => [
            'environment' => 'production',
            'version' => '1.0.0',
        ],
    ],
];

use NewRelic\Service\NewRelicServiceInterface;

class MyController extends AppController
{
    public function index(NewRelicServiceInterface $newRelic)
    {
        // Add custom parameters
        $newRelic->addCustomParameter('user_id', $this->Auth->user('id'));
        
        // Add custom metrics
        $newRelic->addCustomMetric('custom/feature_usage', 1.0);
        
        // Record exceptions
        try {
            // Your code here
        } catch (\Throwable $e) {
            $newRelic->recordException($e);
            throw $e;
        }
    }
}

return [
    'NewRelic' => [
        'customTracers' => [
            'App\Model\Table\UsersTable::findActive',
            'App\Service\CacheService::get',
        ],
    ],
];