PHP code example of palzin-apm / palzin-slim

1. Go to this page and download the library: Download palzin-apm/palzin-slim 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/ */

    

palzin-apm / palzin-slim example snippets


$container->set('palzin', function () {
    $configuration = new \Palzin\Slim\Configuration('PALZIN_APM_INGESTION_KEY');
    $configuration->setUrl('YOUR URL');
    return new Palzin($configuration);
});

use DI\ContainerBuilder;
use Psr\Container\ContainerInterface;

return function (ContainerBuilder $containerBuilder) {
    $containerBuilder->addDefinitions([
        // Other service definitions...

        'palzin' => function (ContainerInterface $container) {
            $configuration = new \Palzin\Slim\Configuration('PALZIN_APM_INGESTION_KEY');
            $configuration->setUrl('YOUR URL');
            return new Palzin\Palzin($configuration);
        }
    ]);
}

$app->add(\Palzin\Slim\WebRequestMonitoring::class);

$app->get('/', function () {
    // Your code here...
})->add(\Palzin\Slim\WebRequestMonitoring::class);

$app->get('/test', function () {
    throw new \Exception('My First Exception.');
})->add(\Palzin\Slim\WebRequestMonitoring::class);

$app->get('/', function (Request $request, Response $response) {
    $this->get('palzin')->addSegment(function () {
        // Your code here...
        sleep(1);
    }, 'sleep');

    return $response;
});

namespace App\Controllers;

use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class TestController
{
    protected $container;

    /**
     * Inject the container to retrieve the palzin instance later.
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function __invoke(Request $request, Response $response)
    {
        $this->container->get('palzin')->addSegment(function () {
            // Your code here...
            sleep(1);
        }, 'sleep');

        $response->getBody()->write('Test route.');

        return $response;
    }
}