PHPackages                             cloud-solutions/zend-sentry - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. cloud-solutions/zend-sentry

Abandoned → [sentry/sdk](/?search=sentry%2Fsdk)ArchivedLibrary[Logging &amp; Monitoring](/categories/logging)

cloud-solutions/zend-sentry
===========================

A Zend Framework 3 module that lets you log to the Sentry.io service.

3.7.0(7y ago)33202.8k192MITPHPPHP &gt;=7.0

Since Feb 11Pushed 6y ago9 watchersCompare

[ Source](https://github.com/cloud-solutions/zend-sentry)[ Packagist](https://packagist.org/packages/cloud-solutions/zend-sentry)[ Docs](https://github.com/cloud-solutions/zend-sentry)[ RSS](/packages/cloud-solutions-zend-sentry/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (35)Used By (2)

IMPORANT NOTICE (September 2019)! We are abandoning/deprecating this package. We will NOT be updating this package to the new Sentry SDK.
=========================================================================================================================================

[](#imporant-notice-september-2019-we-are-abandoningdeprecating-this-package-we-will-not-be-updating-this-package-to-the-new-sentry-sdk)

With the new Sentry SDKs it has become much easier to integrate directly with any project. This package creates way too much boilerplate and most of its code is not needed anymore. As for the JS integration it's much better to install the JS SDK via yarn or npm anyways so you can properly package and automate that stuff too.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#with-the-new-sentry-sdks-it-has-become-much-easier-to-integrate-directly-with-any-project-this-package-creates-way-too-much-boilerplate-and-most-of-its-code-is-not-needed-anymore-as-for-the-js-integration-its-much-better-to-install-the-js-sdk-via-yarn-or-npm-anyways-so-you-can-properly-package-and-automate-that-stuff-too)

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

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b6ffc4c7f0bf87e1bf33892a2f05291e86284931d7303342d64538d54eaf5e23/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636c6f75642d736f6c7574696f6e732f7a656e642d73656e7472792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/cloud-solutions/zend-sentry/?branch=master) [![Build Status](https://camo.githubusercontent.com/a47bdda7f75c662d160055ab05f9bbee9cad4f45cf087ece7c721dd90462e664/68747470733a2f2f7472617669732d63692e6f72672f636c6f75642d736f6c7574696f6e732f7a656e642d73656e7472792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/cloud-solutions/zend-sentry)

ZendSentry is released under the MIT License.

The current version of ZendSentry for ZF3 is `3.7.0`. It supports Zend Framework &gt;= 3.0. For other versions see tags in the 1.\* series as well as 2.\* series. **NB!** We are not supporting the old branches anymore.

Recent Changes
==============

[](#recent-changes)

- 3.7.0: Add option to configure used Ravenjs version, upgrade Ravenjs to `3.27.0`
- 3.6.0: Add static setter to inject CSP nonce (temporary solution)
- 3.5.0: Add support for new Sentry DSN, deprecate old DSN for later removal
- 3.4.0: Add possibility to switch off usage of raven-js CDN
- 3.3.0: Add possibility to pass config options to ravenjs

Introduction
============

[](#introduction)

What's Sentry?
--------------

[](#whats-sentry)

[Sentry](https://www.getsentry.com/welcome/) 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
-----------------

[](#whats-zendsentry)

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

Features and capabilities:

- log uncatched PHP exceptions to Sentry automagically.
- log PHP errors to Sentry automagically.
- log uncatched Javascript errors to Sentry automagically.
- capture Exceptions to Sentry by triggering an event listener.
- log anything you like to Sentry by triggering an event listener.
- ZF ExceptionStrategy for Http as well as the CLI (automatic selection).
- log actions return the Sentry event\_id.
- Raven is registered as a Service.
- override Raven config defaults.
- pass config options to ravenjs.
- configure error messages.
- inject a Content-Security-Policy`nonce for the inline script rendering. Makes it possible for you to create a CSP without`unsafe-inline` as script source.

Installation
============

[](#installation)

This module is available on [Packagist](https://packagist.org/packages/cloud-solutions/zend-sentry). In your project's `composer.json` use:

```
{
    "require": {
        "cloud-solutions/zend-sentry": "3.7.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](#try-it). Happy logging!

Basic Automatic Usage
=====================

[](#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](#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
============

[](#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
==========

[](#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' => 'test@test.com'),
));

```

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
================

[](#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(),
        ]
    );
}

```

Injecting a CSP nonce (NB! temporary solution)
==============================================

[](#injecting-a-csp-nonce-nb-temporary-solution)

If you've already implemented a Content Security Policy in your app, chances are you're using a nonce for dynamic inline javascript. If so, you can now inject your nonce into ZendSentry:

```
ZendSentry::setCSPNonce(ContentSecurityPolicy::getNonce());

```

... where `ContentSecurityPolicy` is your implementation of that http header.

If you inject a nonce, ZendSentry will add it as an attribute to the Raven loading script. Example:

```

    //

```

Please note that we regard this as a temporary solution. It would be much better for ZendSentry to define its own CSP header. Right now Zend Framework is not handling multiple CSP headers the right way (see also [this issue](https://github.com/zendframework/zend-http/issues/159) in `zend-http`).

Configuration options
=====================

[](#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,

/**
 * Should ZendSentry load raven-js via CDN?
 * If you set this to false you'll need to make sure to load raven-js some other way.
 */
'use-ravenjs-cdn' => true,

/**
 * Change the raven-js version loaded via CDN if you need to downgrade or we're lagging behind with updating.
 * No BC breaks, ZendSentry will set the version if your config is missing the key.
 */
'ravenjs-version' => '3.27.0',

/**
 * Alternatively, if not using CDN, you can specify a path or url to raven-js.
 * Set to empty to disable but make sure to load raven-js some other way.
 */
'ravenjs-source' => '/js/raven.min.js',

/**
 * Set raven config options for the getsentry/sentry-php package 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(),

/**
 * Set ravenjs config options for the getsentry/raven-js package here.
 * This will be json encoded and passed to raven-js when doing Raven.install().
 */
'ravenjs-config' => array(),

```

Try it
======

[](#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.');");

```

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 80.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~67 days

Recently: every ~106 days

Total

32

Last Release

2759d ago

Major Versions

0.3.1 → 1.0.02013-09-17

1.5.4 → 2.0.02016-03-31

2.2.1 → 3.0.02016-11-11

2.3.1 → 3.2.02017-07-27

2.4.0 → 3.3.02017-07-27

PHP version history (4 changes)0.1.0PHP &gt;=5.3.0

2.0.0PHP ^5.5 || ^7.0

3.5.0PHP ^5.6 || ^7.0

3.6.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ee9b39ce47b23a653268b4049f45db10c9dbd5f587c5e2b890c6602469c6dd2a?d=identicon)[markushausammann](/maintainers/markushausammann)

---

Top Contributors

[![markushausammann](https://avatars.githubusercontent.com/u/723043?v=4)](https://github.com/markushausammann "markushausammann (59 commits)")[![BnitoBzh](https://avatars.githubusercontent.com/u/2962152?v=4)](https://github.com/BnitoBzh "BnitoBzh (5 commits)")[![metalinspired](https://avatars.githubusercontent.com/u/18539473?v=4)](https://github.com/metalinspired "metalinspired (3 commits)")[![Danielss89](https://avatars.githubusercontent.com/u/632956?v=4)](https://github.com/Danielss89 "Danielss89 (1 commits)")[![Bruce17](https://avatars.githubusercontent.com/u/5036995?v=4)](https://github.com/Bruce17 "Bruce17 (1 commits)")[![chris-moreton](https://avatars.githubusercontent.com/u/1436601?v=4)](https://github.com/chris-moreton "chris-moreton (1 commits)")[![pskt](https://avatars.githubusercontent.com/u/2283090?v=4)](https://github.com/pskt "pskt (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![smknstd](https://avatars.githubusercontent.com/u/2412608?v=4)](https://github.com/smknstd "smknstd (1 commits)")

---

Tags

phpravensentrysentry-servicezend-frameworklogloggingsentryZend Frameworkraven

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cloud-solutions-zend-sentry/health.svg)

```
[![Health](https://phpackages.com/badges/cloud-solutions-zend-sentry/health.svg)](https://phpackages.com/packages/cloud-solutions-zend-sentry)
```

###  Alternatives

[sentry/sentry-laravel

Laravel SDK for Sentry (https://sentry.io)

1.3k114.3M154](/packages/sentry-sentry-laravel)[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k227.1M273](/packages/sentry-sentry)[sentry/sdk

This is a meta package of sentry/sentry. We recommend using sentry/sentry directly.

328134.8M151](/packages/sentry-sdk)[facile-it/sentry-module

This module allows integration of Sentry Client into laminas and mezzio

19372.5k](/packages/facile-it-sentry-module)[jenssegers/raven

Sentry (Raven) error monitoring integration for Laravel projects

90197.2k1](/packages/jenssegers-raven)[e96/yii2-sentry

A Yii2 client for Sentry (http://getsentry.com)

2960.4k](/packages/e96-yii2-sentry)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
