App\Exceptions\Handler) and can be configured to capture both uncaught exceptions and logged errors.illuminate.query, eloquent.*) can be extended to notify Airbrake for non-exception events (e.g., slow queries, failed jobs), enhancing observability without modifying core logic.production vs. staging), aligning with Laravel’s .env configuration.config/app.php), centralizing configuration (API key, filters, ignore patterns) and enabling dependency injection.App\Exceptions\Handler::render() or report() methods to forward errors to Airbrake without disrupting existing logic.Illuminate\Queue\Failed\FailedJob or using queue:failed events.request() helper or middleware, enriching error reports.config/services.php or .env risks exposure. Mitigation: Use Laravel’s Vault or environment variables with strict access controls.queue:work with phpbrake in a separate process).composer.json or fork the package if critical.spatie/laravel-airbrake).assertReported() in PHPUnit) to validate error capture.composer require airbrake/phpbrake
.env:
AIRBRAKE_API_KEY=your_key
config/services.php:
'airbrake' => [
'project_id' => env('AIRBRAKE_PROJECT_ID'),
'environment' => env('APP_ENV'),
],
App\Exceptions\Handler.php:
use Airbrake\Airbrake;
public function report(Throwable $exception)
{
if (app()->bound('airbrake')) {
Airbrake::notify($exception);
}
parent::report($exception);
}
use Airbrake\Airbrake;
class LogErrorsMiddleware
{
public function handle($request, Closure $next)
{
try {
return $next($request);
} catch (Throwable $e) {
Airbrake::notify($e, [
'context' => ['user_id' => auth()->id()]
]);
throw $e;
}
}
}
Illuminate\Queue\Failed\FailedJob or listen to queue:failed events:
use Airbrake\Airbrake;
Event::listen('queue:failed', function ($job, $exception) {
Airbrake::notify($exception, ['job' => $job->payload()]);
});
5xx responses).config/airbrake.php) to avoid hardcoded values.composer why-not to test updates.storage/logs/laravel.log) for deeper analysis./api/payments")..env).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Airbrake API Unavailable | Errors logged locally but not reported. | Fallback to local logging (e.g., Monolog). |
| API Key Compromise | Unauthorized error reporting. | Rotate keys immediately; use short-lived tokens. |
| High Error Volume | API throttling or rate limits. | Implement local buffering/queueing. |
| Payload Size Limits | Truncated stack traces. | Reduce context data or upgrade Airbrake plan. |
| Laravel Cache Issues | Failed error reporting. | Ensure session and cache drivers are healthy. |
How can I help you explore Laravel packages today?