Code Execution Monitoring for Slim based applications.
Server requirements
PHP >= 7.2
Slim >= 4.x
Install
Install the latest package version by:
composer require inspector-apm/inspector-slim
Register On Container
First you have to register the Inspector instance inside the application container in order to make the monitoring agent available within the application.
$app->get('/test',function () {thrownew\Exception('My First Exception.');});
You should receive your first notification in a few seconds.
Add Segments
You can add segments to the transaction's timeline from route functions:
$app->get('/',function (Request $request,Response $response) {/* * Retrieve the inspector instance from the container. */$this->get('inspector')->addSegment(function () {// your code here...sleep(1); },'sleep');return $response;});
If your routes are organized using controllers you need to inject the container in the controller constructor in order to retrieve the inspector agent later during execution:
namespaceApp\Controllers;usePsr\Container\ContainerInterface;usePsr\Http\Message\ResponseInterfaceas Response;usePsr\Http\Message\ServerRequestInterfaceas Request;classTestRouteController{protected $container;/** * Inject the container to retrieve the inspector instance later. */publicfunction__construct(ContainerInterface $container) {$this->container = $container; }publicfunction__invoke(Request $request,Response $response) {// Use the inspector instance from the container.$this->container->get('inspector')->addSegment(function () {// your code here...sleep(1); },'sleep'); $response->getBody()->write('Test route.');return $response; }}