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 Bundle Laravel Package

becklyn/bugsnag-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer:

    composer require becklyn/bugsnag-bundle
    

    Enable it in config/bundles.php:

    Becklyn\BugsnagBundle\BecklynBugsnagBundle::class => ['all' => true],
    
  2. 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%'
    
  3. First Use Case Trigger an error to verify integration:

    use Becklyn\BugsnagBundle\Bugsnag;
    
    // In a controller or service
    Bugsnag::notify(new \RuntimeException('Test error'));
    

Implementation Patterns

Core Workflows

  1. Error Reporting

    • Exceptions: Automatically capture uncaught exceptions by extending the kernel:
      // src/Kernel.php
      public function handleException(Exception $exception, Request $request)
      {
          Bugsnag::notify($exception);
          return parent::handleException($exception, $request);
      }
      
    • Manual Notifications: Log errors explicitly:
      try {
          // Risky operation
      } catch (\Exception $e) {
          Bugsnag::notify($e, [
              'user' => $user->toArray(),
              'context' => 'Payment processing',
          ]);
      }
      
  2. Contextual Data

    • Attach metadata to errors:
      Bugsnag::notify($exception, [
          'releaseStage' => 'staging',
          'customData' => ['user_id' => 123],
      ]);
      
  3. Middleware Integration

    • Log errors from middleware:
      // src/Middleware/ErrorLogger.php
      public function handle(Request $request, Closure $next)
      {
          try {
              return $next($request);
          } catch (\Exception $e) {
              Bugsnag::notify($e);
              throw $e;
          }
      }
      
  4. Event Listeners

    • Capture errors in event subscribers:
      // src/EventListener/ErrorSubscriber.php
      public function onKernelException(GetResponseForExceptionEvent $event)
      {
          Bugsnag::notify($event->getThrowable());
      }
      

Gotchas and Tips

Pitfalls

  1. Deprecated Bundle

    • Last release in 2016 (Symfony 3.x). May not work with newer Symfony/Laravel versions.
    • Mitigation: Fork the repo or use a modern alternative like bugsnag/bugsnag-laravel.
  2. Configuration Overrides

    • Default config may not align with Bugsnag’s latest API. Verify against Bugsnag’s docs.
    • Example: releaseStage vs. releaseStage (deprecated in newer SDKs).
  3. Environment-Specific Keys

    • Ensure BUGSNAG_API_KEY is set in .env for all environments (dev/staging/prod).
  4. Performance Impact

    • Network calls to Bugsnag’s API add latency. Avoid in critical paths (e.g., real-time APIs).

Debugging Tips

  1. Verify Payloads Use Bugsnag::notify() with debug: true to inspect sent data:

    Bugsnag::notify($e, [], ['debug' => true]);
    
  2. Check Logs Enable Symfony’s profiler to see if errors are being captured:

    # config/packages/dev/debug.yaml
    framework:
        profiler: { only_exceptions: false }
    
  3. Test Locally Simulate errors in a staging environment to confirm payloads:

    Bugsnag::notify(new \LogicException('Test local error'));
    

Extension Points

  1. 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);
        }
    }
    
  2. 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']);
        }
    }
    
  3. 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']));
        }
    }
    
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle