Sentry integration with CakePhp

Hi,

I can’t make Sentry works with CakePhp, does anybody around succeed to configure Sentry for this framework ? I would appreciate a little help.
I’ve tried some CakePhp plugins, but they seem outdated comparing to PHP SDK version and I prefer a clean setup with official SDK.

I added Sentry init in my config/bootstrap.php file:

/*
 * Register application error and exception handlers.
 */
$isCli = PHP_SAPI === 'cli';
if ($isCli) {
  (new ConsoleErrorHandler(Configure::read('Error')))->register();
} else {
  Sentry\init(['dsn' => '*****' ]);
}

But here is the error I’m getting when I try to access my web app:

Fatal error: Uncaught Http\Discovery\Exception\DiscoveryFailedException: Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors - Puli Factory is not available - No valid candidate found using strategy "Http\Discovery\Strategy\CommonClassesStrategy". We tested the following candidates: . - No valid candidate found using strategy "Http\Discovery\Strategy\CommonPsr17ClassesStrategy". We tested the following candidates: Nyholm\Psr7\Factory\Psr17Factory, Zend\Diactoros\ResponseFactory, Http\Factory\Diactoros\ResponseFactory, Http\Factory\Guzzle\ResponseFactory, Http\Factory\Slim\ResponseFactory. in /Applications/MAMP/htdocs/winalist/vendor/php-http/discovery/src/Exception/DiscoveryFailedException.php:41 Stack trace: #0 /Applications/MAMP/htdocs/winalist/vendor/php-http/discovery/src/ClassDiscovery.php(79): Http\Discovery\Exception\DiscoveryFailedException::create(Array) #1 /Applications/MAMP/htdocs/winalist/vendor/php-http/discovery/s in /Applications/MAMP/htdocs/winalist/vendor/php-http/discovery/src/ClassDiscovery.php on line 210

Thanks.

How have you installed the Sentry SDK? That error indicates that you don’t have a PSR17 client (like guzzle) available.

This forum post has some options on how to create an exception handling middleware for a CakePHP app using the unified SDK.

I installed Sentry SDK with this command :
composer require sentry/sdk:2.0.2

I tried but having error mentioned earlier.

Looks like php-http adapters have shifted around since the 2.0.2 release of the sentry/sdk meta-package. There is an un-released commit in master that fixes the broken dependencies. Until a new version of sentry/sdk is tagged you can run:

composer require http-interop/http-factory-guzzle:^1.0

to get the missing package will solve the discovery problem you’re having.

Thanks !

Well, package has been updated and this is no longer required :slight_smile: