2017 © Pedro Peláez
 

library sentry-module

Module to integrate Sentry with Zend Framework 2

image

facile-it/sentry-module

Module to integrate Sentry with Zend Framework 2

  • Friday, December 1, 2017
  • by thomasvargiu
  • Repository
  • 4 Watchers
  • 5 Stars
  • 11,933 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 20 Versions
  • 22 % Grown

The README.md

ZF Sentry Module

This module allows integration with Sentry Client into laminas and mezzio., (*1)

Installation

The only supported way to install this module is trough composer. For composer documentation you can refer to getcomposer.org., (*2)

Install with implementations of php-http/async-client-implementation and psr/http-message-implementation:, (*3)

php composer.phar require facile-it/sentry-module php-http/curl-client laminas/laminas-diactoros

Configuration

Client

To configure an instance of the client you can do as below:, (*4)


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 ], ], ], ]; //...

Now you can use the client and the Hub by retrieving it from the Service Locator., (*5)

use Sentry\HubInterface;

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

Error Handler Listener

This module provides a listener for MvcEvent::EVENT_DISPATCH_ERROR and MvcEvent::EVENT_RENDER_ERROR events in order to log the exceptions caught in these events., (*6)

If you want to use it you should register it in your application module., (*7)

Example:

getApplication();
        $container = $application->getServiceManager();
        $eventManager = $application->getEventManager();
        
        /** @var ErrorHandlerListener $errorHandlerListener */
        $errorHandlerListener = $container->get(ErrorHandlerListener::class);
        $errorHandlerListener->attach($eventManager);
    }
}
```

### Log Writer

You can use our log writer to write logs.

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

Usage:

```php

$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]);
```

### Javascript

This module can inject the javascript Raven client library and configure it for you.

```php
 [
        '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',
            ],
        ],
    ],
];

```
In your layout:
```php
= $this->headScript() ?>

Usage with Mezzio (ex zend-expressive)

If you want to use it with Mezzio you should initialize the Sentry client and Hub. You can simply retrieve the HubInterface service to initialize it., (*8)

use Sentry\HubInterface;

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

The Versions

12/04 2016

v0.2.0

0.2.0.0

Module to integrate Sentry with Zend Framework 2

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

12/04 2016

v0.1.0

0.1.0.0

Module to integrate Sentry with Zend Framework 2

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires