bliptrace/cakephp registers a handler on CakePHP’s Error.beforeRender event and sends each rendered exception with its request context. CakePHP 5, PHP 8.2+.
Install from GitHub. This package is not on Packagist yet. Source: github.com/bliptrace/bliptrace-cakephp.
Install
composer config repositories.bliptrace-cakephp vcs https://github.com/bliptrace/bliptrace-cakephp
composer require bliptrace/cakephp:dev-main
Configure
// config/app_local.php
use G8Scope\Php\Env; // reads BLIPTRACE_<NAME>
return [
'G8Scope' => [
'enabled' => filter_var(Env::get('ENABLED', 'true'), FILTER_VALIDATE_BOOL),
'key' => Env::get('KEY'),
'endpoint' => Env::get('ENDPOINT', 'https://ingest.bliptrace.com'),
'environment' => Env::get('ENVIRONMENT', 'production'),
'release' => Env::get('RELEASE'),
'timeout' => 3,
'basePath' => ROOT, // marks your own frames as in-app
'ignoreExceptions' => [
\Cake\Http\Exception\NotFoundException::class,
\Cake\Http\Exception\MethodNotAllowedException::class,
],
'scrubKeys' => ['password', 'token', 'secret', 'authorization'],
],
];
Wire it up
// src/Application.php
use Cake\Core\Configure;
use Cake\Event\EventManager;
use G8Scope\CakePHP\Error\G8ScopeErrorHandler;
public function bootstrap(): void
{
parent::bootstrap();
EventManager::instance()->on(
'Error.beforeRender',
G8ScopeErrorHandler::fromConfig(Configure::read('G8Scope', []))
);
}
Report a handled exception
use Cake\Core\Configure;
use G8Scope\CakePHP\G8ScopeConfig;
use G8Scope\CakePHP\Reporter;
use G8Scope\Php\Client;
$reporter = new Reporter(new Client(G8ScopeConfig::fromArray(Configure::read('G8Scope', []))));
try {
riskyOperation();
} catch (\Throwable $e) {
$reporter->capture($e, $this->request, ['id' => (string) $userId]);
}
To keep the request fast, build during the request and send on shutdown: $env = $reporter->build($e, $request); register_shutdown_function(fn () => $reporter->send($env));