herloct / slim-newrelic
New Relic instrumentation for the Slim framework
Installs: 11 243
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^5.6 || ^7.0
- sobanvuex/php-newrelic: ^2.0
Requires (Dev)
- phpunit/phpunit: ^5.7
- slim/slim: ^3.7
This package is not auto-updated.
Last update: 2024-11-10 03:20:53 UTC
README
This library provides New Relic instrumentation for the Slim framework. When installed this library will ensure that your transactions are properly named and that your exceptions are properly logged in New Relic.
Using @nordsoftware's nordsoftware/lumen-newrelic as reference.
License
See LICENSE
Requirements
Usage
Installation
Run the following command to install the package through Composer:
composer require herloct/slim-newrelic
Bootstrapping
Example index.php
.
$config = [ 'settings' => [ 'displayErrorDetails' => true, // These two are needed so new relic agent could work 'addContentLengthHeader' => false, 'determineRouteBeforeAppMiddleware' => true ], 'errorHandler' => function ($c) { $agent = $c->get(\SobanVuex\NewRelic\Agent::class); $errorHandler = new \Slim\Handlers\Error($c->get('settings')['displayErrorDetails']); return new \Herloct\Slim\Handlers\NewRelicError($agent, $errorHandler); }, \SobanVuex\NewRelic\Agent::class => function ($c) { $agent = new \SobanVuex\NewRelic\Agent( 'Your Application Name', 'YOUR_NEW_RELIC_LICENSE_KEY' ); return $agent; }, \Herloct\Slim\NewRelicTransactionMiddleware::class => function ($c) { $agent = $c->get(\SobanVuex\NewRelic\Agent::class); return new \Herloct\Slim\NewRelicTransactionMiddleware($agent); } ]; $app = new \Slim\App($config); $app->add(\Herloct\Slim\NewRelicTransactionMiddleware::class); $app->get('/hello/{name}', function ($request, $response, $args) { return $response->write("Hello " . $args['name']); })->setName('say_hello'); $app->run();
Customizing transaction names
By default the transaction name will use the route's name. If that fails, it will use the route's pattern.
If this doesn't meet your requirements, extend the Herloct\Slim\NewRelicTransactionMiddleware
class and override the
getTransactionName()
method, then register that middleware class instead.
Running tests
Clone the project and install its dependencies by running:
composer install
Run the following command to run the test suite:
vendor/bin/phpunit