Giter Club home page Giter Club logo

sentry-module's Introduction

ZF Sentry Module

This module allows integration with Sentry Client into laminas and mezzio.

Installation

The only supported way to install this module is trough composer. For composer documentation you can refer to getcomposer.org.

Install with implementations of php-http/async-client-implementation and psr/http-message-implementation:

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:

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.

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.

If you want to use it you should register it in your application module.

Example:

<?php

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);
    }
}

Log Writer

You can use our log writer to write logs.

Example:

<?php

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

Usage:

$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

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

In your layout:

<?= $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.

use Sentry\HubInterface;

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

sentry-module's People

Contributors

thomasvargiu avatar fntlnz avatar alexmanno avatar ildanno avatar gloomy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.