Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Bugsnag Symfony Laravel Package

bugsnag/bugsnag-symfony

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer:

composer require bugsnag/bugsnag-symfony

Register the Bugsnag\Symfony\BugsnagBundle in config/bundles.php (Symfony) or use the Laravel service provider if applicable. Configure via .env or config/services.php:

BUGSNAG_API_KEY=your_api_key
BUGSNAG_ENDPOINT=https://notify.bugsnag.com

For Laravel, publish the config:

php artisan vendor:publish --provider="Bugsnag\Symfony\BugsnagBundle\BugsnagBundle" --tag="config"

First use case: Automatic error reporting. Install the bundle, configure your API key, and let Bugsnag capture exceptions automatically. Verify by triggering an unhandled exception (e.g., 1/0 in a route).


Implementation Patterns

Symfony Integration

  1. Bundle Registration: Add to config/bundles.php:

    Bugsnag\Symfony\BugsnagBundle\BugsnagBundle::class => ['all' => true],
    

    For Symfony 5.4+, leverage autowiring to inject BugsnagClient into services:

    use Bugsnag\Client;
    
    class MyService {
        public function __construct(private Client $bugsnag) {}
    }
    
  2. Manual Error Reporting: Explicitly notify Bugsnag for critical failures:

    $this->bugsnag->notify(new \RuntimeException('Custom error message'));
    
  3. Contextual Data: Attach metadata (e.g., user ID, request data) to reports:

    $this->bugsnag->notify($exception)
        ->addTab('Request', ['data' => $request->all()]);
    

Laravel Integration

  1. Service Provider: Bind the Bugsnag client in AppServiceProvider:

    $this->app->singleton(\Bugsnag\Client::class, function ($app) {
        return new \Bugsnag\Client(config('bugsnag.api_key'));
    });
    
  2. Exception Handling: Extend Laravel’s App\Exceptions\Handler to notify Bugsnag:

    public function report(Throwable $exception) {
        if (app()->bound(\Bugsnag\Client::class)) {
            app(\Bugsnag\Client::class)->notify($exception);
        }
        parent::report($exception);
    }
    
  3. Middleware for API Errors: Use middleware to catch API-specific errors:

    use Bugsnag\Client;
    
    class BugsnagMiddleware {
        public function handle($request, Closure $next, Client $bugsnag) {
            try {
                return $next($request);
            } catch (\Throwable $e) {
                $bugsnag->notify($e)->addTab('API Request', $request->all());
                throw $e;
            }
        }
    }
    

Gotchas and Tips

Breaking Changes (v2.0.0)

  1. PHP 7.2+ Requirement:

    • Impact: Codebases using PHP <7.2 will fail. Update your environment or use a legacy branch if available.
    • Fix: Run php -v to check your version. Update via pecl upgrade or your system package manager.
  2. Symfony 5.4+ Requirement:

    • Impact: Symfony <5.4 may break autowiring or bundle registration.
    • Fix: For older Symfony, pin to v1.x of the package or upgrade Symfony:
      composer require symfony/*:^5.4
      

Debugging

  1. Disable Auto-Notification: Temporarily disable Bugsnag in config/services.php:

    'bugsnag' => [
        'enabled' => env('BUGSNAG_ENABLED', false),
    ],
    
  2. Test Locally: Use the BUGSNAG_ENDPOINT to point to a local mock server during development:

    BUGSNAG_ENDPOINT=http://localhost:3000/notify
    
  3. Check Ignored Exceptions: Configure config/bugsnag.php to ignore specific exceptions (e.g., HttpException):

    'ignore_exceptions' => [
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
    ],
    

Extension Points

  1. Custom Error Formatting: Override the Bugsnag\Symfony\BugsnagBundle\EventListener\ExceptionListener to modify payloads:

    $listener->setBugsnagClient($customClient);
    
  2. Symfony 8 Features: Leverage Symfony 8’s improved dependency injection:

    # config/services.yaml
    Bugsnag\Client: '@bugsnag.client'
    
  3. Laravel Scout Integration: For Laravel, pair with Scout to track model-level errors:

    try {
        Model::scout()->search('query');
    } catch (\Exception $e) {
        $bugsnag->notify($e)->addTab('Scout Query', ['query' => 'search']);
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky