Installation Add the bundle via Composer:
composer require becklyn/bugsnag-bundle
Enable it in config/bundles.php:
Becklyn\BugsnagBundle\BecklynBugsnagBundle::class => ['all' => true],
Configuration Publish the default config:
php bin/console config:dump-reference BecklynBugsnagBundle
Update config/packages/becklyn_bugsnag.yaml with your Bugsnag API key:
becklyn_bugsnag:
api_key: '%env(BUGSNAG_API_KEY)%'
environment: '%kernel.environment%'
First Use Case Trigger an error to verify integration:
use Becklyn\BugsnagBundle\Bugsnag;
// In a controller or service
Bugsnag::notify(new \RuntimeException('Test error'));
Error Reporting
// src/Kernel.php
public function handleException(Exception $exception, Request $request)
{
Bugsnag::notify($exception);
return parent::handleException($exception, $request);
}
try {
// Risky operation
} catch (\Exception $e) {
Bugsnag::notify($e, [
'user' => $user->toArray(),
'context' => 'Payment processing',
]);
}
Contextual Data
Bugsnag::notify($exception, [
'releaseStage' => 'staging',
'customData' => ['user_id' => 123],
]);
Middleware Integration
// src/Middleware/ErrorLogger.php
public function handle(Request $request, Closure $next)
{
try {
return $next($request);
} catch (\Exception $e) {
Bugsnag::notify($e);
throw $e;
}
}
Event Listeners
// src/EventListener/ErrorSubscriber.php
public function onKernelException(GetResponseForExceptionEvent $event)
{
Bugsnag::notify($event->getThrowable());
}
Deprecated Bundle
bugsnag/bugsnag-laravel.Configuration Overrides
releaseStage vs. releaseStage (deprecated in newer SDKs).Environment-Specific Keys
BUGSNAG_API_KEY is set in .env for all environments (dev/staging/prod).Performance Impact
Verify Payloads
Use Bugsnag::notify() with debug: true to inspect sent data:
Bugsnag::notify($e, [], ['debug' => true]);
Check Logs Enable Symfony’s profiler to see if errors are being captured:
# config/packages/dev/debug.yaml
framework:
profiler: { only_exceptions: false }
Test Locally Simulate errors in a staging environment to confirm payloads:
Bugsnag::notify(new \LogicException('Test local error'));
Custom Error Filters
Override Becklyn\BugsnagBundle\Bugsnag to sanitize data:
// src/Service/Bugsnag.php
class CustomBugsnag extends \Becklyn\BugsnagBundle\Bugsnag
{
protected function filterSensitiveData(array $data): array
{
unset($data['password']);
return parent::filterSensitiveData($data);
}
}
Async Reporting Queue notifications for non-critical errors:
// src/Command/QueueBugsnagCommand.php
public function handle()
{
while ($error = $this->queue->pop('bugsnag')) {
Bugsnag::notify($error['exception'], $error['data']);
}
}
Integration with Monolog Bridge Bugsnag with Symfony’s logger:
// src/Service/BugsnagHandler.php
use Monolog\Handler\AbstractProcessingHandler;
use Becklyn\BugsnagBundle\Bugsnag;
class BugsnagHandler extends AbstractProcessingHandler
{
public function __construct()
{
parent::__construct(Bugsnag::LEVEL_ERROR);
}
protected function write(array $record): void
{
Bugsnag::notify(new \RuntimeException($record['message']));
}
}
How can I help you explore Laravel packages today?