Setting Up Error Tracking (Bugsnag) for Your Web Application
Bugsnag is a commercial alternative to Sentry with focus on release stability. Key metric — Stability Score: percentage of sessions without errors. More convenient than raw error counts when deciding if a release is ready to ship.
Free plan: 7500 errors/month for 1 project.
Installation PHP / Laravel
composer require bugsnag/bugsnag-laravel
php artisan bugsnag:install your-api-key-here
In .env:
BUGSNAG_API_KEY=your_32_char_api_key
BUGSNAG_APP_VERSION=1.0.0
BUGSNAG_RELEASE_STAGE=production
config/bugsnag.php after publishing:
return [
'api_key' => env('BUGSNAG_API_KEY'),
'app_version' => env('BUGSNAG_APP_VERSION'),
'release_stage' => env('BUGSNAG_RELEASE_STAGE', 'production'),
'notify_release_stages' => ['production', 'staging'],
'filters' => ['password', 'token', 'secret', 'api_key'],
'notify_endpoint' => 'https://notify.bugsnag.com',
'sessions_endpoint' => 'https://sessions.bugsnag.com',
'auto_capture_sessions' => true,
];
Service Provider registers automatically. In app/Exceptions/Handler.php for Laravel 9-10:
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
public function register(): void
{
$this->reportable(function (Throwable $e) {
Bugsnag::notifyException($e);
});
}
Context and Metadata
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
// Set user (automatically if auth configured)
Bugsnag::setUser([
'id' => $user->id,
'name' => $user->name,
'email' => $user->email,
]);
// Add custom tabs to report
Bugsnag::registerCallback(function ($report) {
$report->setMetaData([
'subscription' => [
'plan' => auth()->user()?->plan,
'trial_ends' => auth()->user()?->trial_ends_at,
],
]);
});
// Manual submission with additional data
Bugsnag::notifyException(
new \RuntimeException('Stripe webhook failed'),
function ($report) use ($payload) {
$report->setSeverity('warning');
$report->setMetaData(['webhook' => ['event' => $payload['type']]]);
}
);
JavaScript / React
npm install @bugsnag/js @bugsnag/plugin-react
// src/bugsnag.ts
import Bugsnag from '@bugsnag/js';
import BugsnagPluginReact from '@bugsnag/plugin-react';
import React from 'react';
Bugsnag.start({
apiKey: import.meta.env.VITE_BUGSNAG_API_KEY,
plugins: [new BugsnagPluginReact()],
releaseStage: import.meta.env.MODE,
});
export const ErrorBoundary = Bugsnag.getPlugin('react')
?.createErrorBoundary(React);
Dashboard gives quick insights into stability trends per release.
Timeline
Basic setup for backend and frontend: 1-2 hours. Full integration with release tracking and custom reporting: 3-4 hours.







