1. Go to this page and download the library: Download sirix/sentry-psr 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/ */
use Psr\Container\ContainerInterface;
use Sirix\SentryPsr\Middleware\SentryErrorMiddleware;
return function (App $app, ContainerInterface $container): void {
$app->pipe(SentryErrorMiddleware::class);
// routes and application middleware after Sentry
};
use Sirix\SentryPsr\Lifecycle\SentryLifecycle;
use Sirix\SentryPsr\Reporter\SentryReporter;
final readonly class JobRunner
{
public function __construct(
private SentryLifecycle $lifecycle,
private SentryReporter $reporter,
) {}
public function run(Job $job): void
{
$this->lifecycle->withIsolatedScope(function () use ($job): void {
$this->reporter->setTag('job', $job->name());
$this->reporter->setContext('job', ['id' => $job->id()]);
$job->handle();
});
$this->lifecycle->flush();
}
}
use Sentry\State\HubInterface;
use Sirix\SentryPsr\ConsoleEventDispatcher\ConsoleEventDispatcherFactory;
use Sirix\SentryPsr\Lifecycle\SentryLifecycle;
use Sirix\SentryPsr\Listener\SentryCommandListener;
use Sirix\SentryPsr\Listener\SentryCommandListenerFactory;
use Symfony\Component\EventDispatcher\EventDispatcher;
return [
'dependencies' => [
'factories' => [
HubInterface::class => Sirix\SentryPsr\Hub\SentryHubFactory::class,
SentryLifecycle::class => Sirix\SentryPsr\Lifecycle\SentryLifecycleFactory::class,
SentryCommandListener::class => SentryCommandListenerFactory::class,
EventDispatcher::class => ConsoleEventDispatcherFactory::class,
],
],
];
use Sirix\SentryPsr\Reporter\SentryReporter;
final readonly class CheckoutService
{
public function __construct(private SentryReporter $sentry) {}
public function checkout(): void
{
$this->sentry->setTag('feature', 'checkout');
$this->sentry->setUser(['id' => '123']);
try {
// ...
} catch (\Throwable $exception) {
$this->sentry->captureException($exception, ['step' => 'payment']);
throw $exception;
}
}
}
'sentry_psr' => [
'set_current_hub' => false,
],
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.