Skip to content

arueckauer/mezzio-sentry-delegator

Repository files navigation

mezzio-sentry-delegator

Mezzio Delegator and ErrorListener for Sentry

This package provides an initialization wrapper for Sentry and the ability to capture Throwables in Sentry through an ErrorListener for the Stratigility ErrorHandler middleware.

Installation

Via Composer

composer require arueckauer/mezzio-sentry-delegator

Configuration

Provide a dsn for Sentry and possible other configuration options in the project's configuration, e.g. config/autoload/services.local.php. Go to the PHP configure documentation to select the dsn for a project.

<?php

declare(strict_types = 1);

use Sentry\Options as SentryOptions;

return [
    // [..]
    SentryOptions::class => [
        'dsn' => 'https://<key>@<account-id>.ingest.sentry.io/<project-id>',
    ],
];

Initialize Sentry

To initialize Sentry, add the following line to the anonymous function in public/index.php.

(new MezzioSentryDelegator\SentryInitializer())($container);

Attach Listener by wiring delegator

Declare the delegator dependency in the project's configuration, e.g. config/autoload/dependencies.global.php.

<?php

declare(strict_types = 1);

use MezzioSentryDelegator\Delegator;
use Laminas\Stratigility\Middleware\ErrorHandler;

class ConfigProvider
{
    public function __invoke() : array
    {
        return [
            'dependencies' => [
                'delegators' => [
                    ErrorHandler::class => [
                        Delegator::class,
                    ],
                ],
            ],
        ];
    }
}

About

Mezzio Delegator and ErrorListener for Sentry

Topics

Resources

License

Stars

Watchers

Forks

Languages