Skip to content
CakePHP plugin integration for Sentry
Branch: master
Clone or download
o0h Merge pull request #6 from Connehito/update-readme-abount-send-callback
Update README about send_callback fixed #3
Latest commit 6f1e30e Apr 20, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
config 💄 cosmetic change bootstrap.php Feb 27, 2018
src Declare type with imported namespaces Feb 27, 2018
tests Fix test Feb 27, 2018
.gitignore #2 set composer.json and .gitignore Dec 11, 2017
.travis.yml add php version for build Mar 26, 2018
LICENSE Add license Apr 1, 2018 Update README about send_callback Apr 20, 2018
composer.json fix composer.json Feb 27, 2018
phpcs.xml Rename phpcs.xml.dist to phpcs.xml Feb 27, 2018
phpunit.xml Fix phpunit.xml Feb 27, 2018

CakePHP Sentry Plugin

CakePHP integration for Sentry.

Build Status codecov MIT License


  • PHP 7.0+
  • CakePHP 3.5+
  • and Sentry account


With composer install.

composer require connehito/cake-sentry


Set config files.

in config/bootstrap.php

Plugin::load('Connehito/CakeSentry', ['bootstrap' => true]);
// in `config/app.php`
  'Sentry' => [

or use cake command.

bin/cake plugin load Connehito/CakeSentry --bootstrap

That's all! 🎉

Advanced Usage

Ignore noisy exceptions

You can filter out exceptions that make a fuss and harder to determine the issues to address(like PageNotFoundException) Set exceptions not to log in Error.skipLog.


// in `config/app.php`
'Error' => [
    'skipLog' => [

ref: CakePHP Cookbook

Send more context

Client dispatch CakeSentry.Client.beforeCapture event before sending error to sentry.
You can set context with EventListener.Calling Raven_Client's API or returning values, error context will be sent. The Returned values will be passed to Raven_Client::captureMessage() 3rd arguments(Additional attributes to pass with this event).

Now, cake-sentry supports to get Request instance in implemented event via $event->getSubject()->getRequest().


use Cake\Event\Event;
use Cake\Event\EventListenerInterface;

class SentryErrorContext implements EventListenerInterface
    public function implementedEvents()
        return [
            'CakeSentry.Client.beforeCapture' => 'setContext',

    public function setContext(Event $event)
        $request = $event->getSubject()->getRequest();
        $request->trustProxy = true;
        $raven = $event->getSubject()->getRaven();
                'ip_address' => $request->clientIp()
            'app_version' => $request->getHeaderLine('App-Version') ?: 1.0,

        return [
            'extra' => [
                'foo' => 'bar',

And in config/bootstrap.php

EventManager::instance()->on(new SentryErrorContext());

ref: Sentry official PHP SDK document.

Register send callback

The plugin allows you to inject send_callback option to Raven client.
It will be called in after client send data to Sentry.
See also offcial doc.


// In app.php, setup callback closure for receiving event id from Raven.
// This sample enables you to get "Event ID" via `$Session` in your controller.
// cf)
'Sentry' => [
    'dsn' => env('SENTRY_DSN'),
    'options' => [
        'send_callback' => function ($data) {
            $request = \Cake\Http\ServerRequestFactory::fromGlobals();
            $session = $request->getSession();
            $session->write('last_event_id', $data['event_id']);


Pull requests and feedback are very welcome :)
on GitHub at .


The plugin is available as open source under the terms of the MIT License.

You can’t perform that action at this time.