Download the PHP package benborla/zend-sentry without Composer

On this page you can find all versions of the php package benborla/zend-sentry. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package zend-sentry

A Zend Framework module that lets you log exceptions, errors or whatever you wish to the Sentry service.

Scrutizier analysis: Scrutinizer Code Quality Build Status

ZendSentry is released under the New BSD License.

The current version of ZendSentry for ZF2 is 2.4.0. It supports Zend Framework >= 2.5.3. For older versions see the legacy branch and tags in the 1.* series. For ZF3 compatible versions, please install releases in the 3.* branch.

Important Changes

Introduction

What's Sentry?

Sentry is an online service to which you can log anything including your exceptions and errors. Sentry creates nice reports in real time and aggregates your logged data for you.

What's ZendSentry

It is a module that builds the bridge between your Zend Framework 2 application and the Sentry service. It's extremely easy to setup and does a lot of things out-of-the-box.

Current features:

Installation

This module is available on Packagist. In your project's composer.json use:

{   
    "require": {
        "cloud-solutions/zend-sentry": "2.4.0"
}

Run php composer.phar update to download it into your vendor folder and setup autoloading.

Now copy zend-sentry.local.php.dist to yourapp/config/autoload/zend-sentry.local.php and add your Sentry API key. Then copy zend-sentry.global.php.dist to the same place, also removing .dist. Adjust settings, if needed.

Add ZendSentry to the modules array in your application.config.php, preferably as the first module.

That's it. There's nothing more you need to do, everything works at that stage, try it. Happy logging!

Basic Automatic Usage

Again, you don't need to write a single line of code to make this work. The default settings will make sure Sentry is registered as both error and exception handler, try it by triggering and error or throwing around some exceptions. You should instantly see them in your Sentry dashboard. ZendSentry also packages its own ExceptionStrategies to make sure, exceptions ZF would otherwise intercept, are logged.

Manual Usage

Additonally, the module registers a log event listener on application level. So you can trigger custom log events from anywhere in your application.

In a controller, you may do:

$this->getEventManager()->trigger('log', $this, array(
    'priority' => \Zend\Log\Logger::INFO, 
    'message' => 'I am a message and I have been logged'
));

Or you can store the returned Sentry event_id for processing:

$eventID = $this->getEventManager()->trigger('log', $this, array(
    'priority' => \Zend\Log\Logger::INFO,
    'message' => 'I am a message and I have been logged'
));

Now you can tell your users or API consumers the ID so they can referr to it, e.g. when asking for support.

Make sure to pass "log" as the first parameter and $this or a custom context string as second parameter. Keep this consistent as Sentry will use this for grouping your log entries. As the third parameter, you want to pass an array with a priority key and a message key. It's best to use the priorities provided by the Zend Framework. They will be mapped onto Sentry's own priorities.

Besides the fact that uncaught exceptions and errors are automatically logged, you may also log caught or uncaught exceptions manually by using the respective listener directly:

try {
    throw new Exception('throw and catch');
} catch (Exception $exception) {
    $result = $this->getEventManager()->trigger('logException', $this, array('exception' => $exception));

    //get Sentry event_id by retrieving it from the EventManager ResultCollection
    $eventID = $result->last();
}

Using Tags

You can also pass your own tags to Sentry. The service will automatically create filtering and sorting for these tags. When using the log event, you can optionally pass tags like this:

$this->getEventManager()->trigger('log', $this, array(
    'priority' => \Zend\Log\Logger::INFO,
    'message' => 'I am a message with a language tag',
    'tags' => array('language' => 'en'),
    'extra' => array('email' => '[email protected]'),
));

If using the logException event manually, you can also pass along tags:

try {
    throw new Exception('throw and catch with tags');
} catch (Exception $exception) {
    $this->getEventManager()->trigger('logException', $this, array('exception' => $exception, 'tags' => array('language' => 'fr')));
}

NB! Every tag needs a key and a value.

See how to use tags for automagically logged exceptions below.

Raven as Service

The module registers the Raven_Client as an application wide service. Usually you don't want to access it directly because triggering the event listeners leaves you with cleaner code. One example where the direct usage of Raven can be helpful is for adding user context. For example you might want to do something like this during your bootstrap:

if ($authenticationService->hasIdentity()) {
    $ravenClient = $this->serviceManager->get('raven');
    $ravenClient->user_context($authenticationService->getIdentity()->userID);
}

You can also use Raven directly, if you would like to add some tags to the context, which will be sent with every automatic entry. You might want to do something like this e.g. in your AbstractActionController::preDispatch():

$serviceManager = $mvcEvent->getApplication()->getServiceManager();
if ($serviceManager->has('raven')) {
    $ravenClient = $serviceManager->get('raven');
    $ravenClient->tags_context(
        [
            'locale'  => $this->translator()->getLocale(),
            ...
        ]
    );
}

Configuration options

Just for the record, a copy of the actual global configuration options:

/**
 * Turn ZendSentry off or on as a whole package
 */
'use-module' => true,

/**
 * Attach a generic logger event listener so you can log custom messages from anywhere in your app
 */
'attach-log-listener' => true,

/**
 * Register the Sentry logger as PHP error handler
 */
'handle-errors' => true,

/**
 * Should the previously registered error handler be called as well?
 */
'call-existing-error-handler' => true,

/**
 * Register Sentry as shutdown error handler
 */
'handle-shutdown-errors' => true,

/**
 * Register the Sentry logger as PHP exception handler
 */
'handle-exceptions' => true,

/**
 * Should the previously registered exception handler be called as well
 */
'call-existing-exception-handler' => true,

/**
 * Which errors should be reported to sentry (bitmask), e. g. E_ALL ^ E_DEPRECATED
 * Defaults to -1 to report all possible errors (equivalent to E_ALL in >= PHP 5.4)
 */
'error-reporting' => -1,

/**
 * Should exceptions be displayed on the screen?
 */
'display-exceptions' => false,

/**
 * If Exceptions are displayed on screen, this is the default message
 */
'default-exception-message' => 'Oh no. Something went wrong, but we have been notified. If you are testing, tell us your eventID: %s',

/**
 * If Exceptions are displayed on screen, this is the default message in php cli mode
 */
'default-exception-console-message' => "Oh no. Something went wrong, but we have been notified.\n",

/**
 * Should Sentry also log javascript errors?
 */
'handle-javascript-errors' => true,

/**
 * Set raven config options here.
 * Raven has sensible defaults set in Raven_Client, if you need to override them, this is where you can do it.
 */
'raven-config' => array(),

Try it

A few ideas how to try the different features from a Controller or View:

// Test logging of PHP errors
// trigger_error('can I trigger an error from a controller');

// Test logging of PHP exceptions
// throw new \Exception('Some exception gets logged.');

// Throw a javascript error and see it logged (add to view or layout)
// $headScript->appendScript("throw new Error('A javascript error should be logged.');");

All versions of zend-sentry with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package benborla/zend-sentry contains the following files

Loading the files please wait ....