bliptrace / cakephp
CakePHP SDK for Bliptrace — auto-captures exceptions and ships them to the ingest API. Thin adapter over bliptrace/php.
Requires
- php: ^8.2
- bliptrace/php: ^2.0
Requires (Dev)
- laravel/pint: ^1.0
- pestphp/pest: ^3.0
Suggests
- cakephp/cakephp: ^5.0
Provides
None
Conflicts
None
Replaces
None
README
A thin CakePHP adapter for Bliptrace — it auto-captures exceptions from your CakePHP application and ships them to the Bliptrace ingest API.
It is a lightweight integration over the runtime bliptrace/php
client: a Cake error-handling hook, config glue, request-context enrichment and
a Reporter. It never throws into the host app — a slow or unavailable ingest
endpoint will never break your application.
The project is resolved server-side from the ingest key. It is never sent in the payload (anti-spoof).
Installation
composer require bliptrace/cakephp
Requires PHP 8.2+ and CakePHP 5.x.
Configuration
Add a Bliptrace block to your CakePHP configuration (e.g. config/app_local.php
or via Configure::write()), reading secrets from the environment:
// config/app_local.php use Bliptrace\Php\Env; // reads BLIPTRACE_<NAME> return [ 'Bliptrace' => [ 'enabled' => filter_var(Env::get('ENABLED', 'true'), FILTER_VALIDATE_BOOL), 'key' => Env::get('KEY'), 'endpoint' => Env::get('ENDPOINT', 'https://ingest.bliptrace.com/v1/ingest'), 'environment' => Env::get('ENVIRONMENT', 'production'), 'release' => Env::get('RELEASE'), 'timeout' => 3, 'maxFrames' => 30, 'maxMessage' => 2000, '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'], ], ];
Env names:
Bliptrace\Php\Env::get('KEY')(frombliptrace/php^2.0) readsBLIPTRACE_KEY.
| Key | Default | Notes |
|---|---|---|
enabled |
true |
Master kill switch. |
key |
null |
Ingest key. No key → nothing is shipped. |
endpoint |
https://ingest.bliptrace.com/v1/ingest |
Ingest URL (a bare base URL also works: /v1/ingest is appended when missing). Sent with X-Ingest-Key. |
environment |
production |
|
release |
null |
Version/commit of your deploy. |
timeout |
3 |
Transport timeout (seconds). |
maxFrames |
30 |
Max stack frames captured. |
maxMessage |
2000 |
Max message length. |
basePath |
'' |
App root; frames under it (and not in /vendor/) are flagged in-app. |
ignoreExceptions |
[] |
Fully-qualified exception classes to skip. |
scrubKeys |
[] |
Context keys to scrub before sending. |
Wiring into CakePHP
CakePHP 5 routes every rendered exception through Cake\Error\ErrorTrap, which
dispatches an Error.beforeRender event. Register the Bliptrace handler against
that event in your src/Application.php:
use Cake\Core\Configure; use Cake\Error\ErrorTrap; use Cake\Event\EventManager; use Bliptrace\CakePHP\Error\BliptraceErrorHandler; public function bootstrap(): void { parent::bootstrap(); $handler = BliptraceErrorHandler::fromConfig(Configure::read('Bliptrace', [])); // Listen on the global event manager so any ErrorTrap instance is covered. EventManager::instance()->on('Error.beforeRender', $handler); }
Alternatively, attach it to the ErrorTrap you build in middleware:
use Cake\Error\Middleware\ErrorHandlerMiddleware; use Cake\Error\ErrorTrap; $errorTrap = new ErrorTrap(Configure::read('Error')); $errorTrap->getEventManager()->on( 'Error.beforeRender', BliptraceErrorHandler::fromConfig(Configure::read('Bliptrace', [])) ); $middlewareQueue->add(new ErrorHandlerMiddleware($errorTrap));
The handler pulls the exception (and the request, if present) out of the event,
strips Authorization/Cookie headers, builds the envelope and ships it. Any
failure inside the handler is swallowed.
Manual capture
You can also report exceptions yourself — useful for caught/handled errors:
use Cake\Core\Configure; use Bliptrace\CakePHP\BliptraceConfig; use Bliptrace\CakePHP\Reporter; use Bliptrace\Php\Client; $reporter = new Reporter(new Client( BliptraceConfig::fromArray(Configure::read('Bliptrace', [])) )); try { riskyOperation(); } catch (\Throwable $e) { // Pass the current request (a Cake ServerRequest) for context, plus optional user. $reporter->capture($e, $this->request, ['id' => (string) $userId]); }
To avoid blocking the response, build the envelope during the request and ship it on shutdown:
$envelope = $reporter->build($e, $request); register_shutdown_function(fn () => $reporter->send($envelope));
Testing
This package's own tests depend only on bliptrace/php (no CakePHP), so they run
fast. The Cake-specific class guards its CakePHP references via duck-typing and
is safe to autoload without cakephp/cakephp installed.
composer install
composer test
Licence
MIT. See LICENSE. British spelling throughout.