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.
See LICENSE
Run the following command to install the package through Composer:
composer require herloct/slim-newrelic
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();
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.
Clone the project and install its dependencies by running:
composer install
Run the following command to run the test suite:
vendor/bin/phpunit