PHP code example of facile-it / sentry-module

1. Go to this page and download the library: Download facile-it/sentry-module 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/ */

    

facile-it / sentry-module example snippets



return [
    'sentry' => [
        'disable_module' => false,
        'options' => [
            'dsn' => '',
            // other sentry options
            // https://docs.sentry.io/error-reporting/configuration/?platform=php
        ],
        'javascript' => [
            'inject_script' => false,
            'script' => [
                'src' => 'https://browser.sentry-cdn.com/5.6.3/bundle.min.js',
                'integrity' => 'sha384-/Cqa/8kaWn7emdqIBLk3AkFMAHBk0LObErtMhO+hr52CntkaurEnihPmqYj3uJho',
                'crossorigin' => 'anonymous',
            ],
            'options' => [
                'dsn' => '',
                // other sentry options
                // https://docs.sentry.io/error-reporting/configuration/?platform=php
            ],
        ],
    ],
];
//...

use Sentry\HubInterface;

$hub = $this->getServiceLocator()->get(HubInterface::class);



namespace App;

use Facile\SentryModule\Listener\ErrorHandlerListener;
use Laminas\Mvc\MvcEvent;

class Module 
{
    public function onBootstrap(MvcEvent $e): void
    {
        $application = $e->getApplication();
        $container = $application->getServiceManager();
        $eventManager = $application->getEventManager();
        
        /** @var ErrorHandlerListener $errorHandlerListener */
        $errorHandlerListener = $container->get(ErrorHandlerListener::class);
        $errorHandlerListener->attach($eventManager);
    }
}



// global.php
return [
    'log' => [
        'application.log' => [
            'writers' => [
                [
                    'name' => \Facile\SentryModule\Log\Writer\Sentry::class,
                    'options' => [
                        'filters' => [
                            [
                                'name' => 'priority',
                                'options' => [
                                    'priority' => \Laminas\Log\Logger::ERR,
                                ],
                            ],
                        ],
                    ],
                ],
            ]
        ],
    ],
];


$logger->crit('Log this message');

// or with exceptions, to see the correct trace in sentry:
$e = new \RuntimeException('test-exception');
$logger->crit($e->getMessage(), ['exception' => $e]);



// facile-sentry.module.local.php
return [
    'sentry' => [
        'javascript' => [
            'inject_script' => true, // enable it
            'options' => [
                'dsn' => '',
                // other sentry options
                // https://docs.sentry.io/error-reporting/configuration/?platform=php
            ],
            // script options (defaults)
            'script' => [
                'src' => 'https://browser.sentry-cdn.com/5.6.3/bundle.min.js',
                'integrity' => 'sha384-/Cqa/8kaWn7emdqIBLk3AkFMAHBk0LObErtMhO+hr52CntkaurEnihPmqYj3uJho',
                'crossorigin' => 'anonymous',
            ],
        ],
    ],
];


<?= $this->headScript() 

use Sentry\HubInterface;

$container->get(HubInterface::class);

php composer.phar