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

Rollbar Php Symfony Bundle Laravel Package

ddsimeonov/rollbar-php-symfony-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle

    composer require ddsimeonov/rollbar-php-symfony-bundle
    

    Ensure your composer.json includes "symfony/framework-bundle": "^5.0" or higher.

  2. Configure the Bundle Add to config/bundles.php:

    return [
        // ...
        Ddsimeonov\RollbarBundle\DdsimeonovRollbarBundle::class => ['all' => true],
    ];
    
  3. Environment Configuration Add Rollbar credentials to .env:

    ROLLBAR_ACCESS_TOKEN=your_access_token_here
    ROLLBAR_ENVIRONMENT=production|staging|development
    
  4. First Error Capture Trigger an exception in a controller or service:

    throw new \RuntimeException('Test error for Rollbar');
    

    Verify the error appears in your Rollbar dashboard.


Where to Look First

  • Bundle Docs: Rollbar Symfony SDK
  • Configuration Reference: config/packages/ddsimeonov_rollbar.yaml (auto-generated after installation).
  • Event Listeners: Check src/EventListener/RollbarListener.php for custom logic hooks.

Implementation Patterns

Core Workflows

  1. Automatic Error Capture The bundle auto-captures:

    • Exceptions thrown in controllers, services, or CLI commands.
    • HTTP 500 errors (via Symfony’s ExceptionListener).
    • Logged errors (via Monolog integration).

    Example: No manual code changes needed for most exceptions.

  2. Manual Error Reporting Explicitly report errors with:

    use Ddsimeonov\RollbarBundle\Rollbar;
    
    public function someAction(Rollbar $rollbar) {
        try {
            // Risky code
        } catch (\Exception $e) {
            $rollbar->critical('Custom error message', [
                'context' => ['user_id' => 123],
                'extra' => ['custom_data' => 'value']
            ]);
        }
    }
    
  3. CLI Error Tracking Errors in console commands are automatically captured. Example:

    php bin/console your:command --with-errors
    
  4. Contextual Data Attach metadata to errors:

    $rollbar->info('User login', [
        'user' => $user->toArray(),
        'request' => $request->toArray()
    ]);
    

Integration Tips

  • Monolog Integration Forward Monolog logs to Rollbar by configuring monolog.rollbar_handler in config/packages/monolog.yaml:

    monolog:
        handlers:
            rollbar:
                type: service
                id: Ddsimeonov\RollbarBundle\Monolog\RollbarHandler
                level: error
    
  • Custom Data Enrichment Use Symfony’s kernel.request event to add request context:

    // src/EventListener/RollbarContextListener.php
    public function onKernelRequest(GetResponseEvent $event) {
        $rollbar = $event->getContainer()->get('rollbar');
        $rollbar->setPerson(['id' => $event->getRequest()->get('user_id')]);
    }
    
  • Environment-Specific Config Override settings per environment in config/packages/ddsimeonov_rollbar.yaml:

    ddsimeonov_rollbar:
        environment: '%env(ROLLBAR_ENVIRONMENT)%'
        access_token: '%env(ROLLBAR_ACCESS_TOKEN)%'
        enabled: '%kernel.debug% ? false : true%' # Disable in dev
    

Gotchas and Tips

Pitfalls

  1. Sensitive Data Leakage Avoid logging passwords, tokens, or PII. Use sanitize():

    $rollbar->error('Failed payment', [
        'card' => $request->request->get('card_number', '')->sanitize()
    ]);
    
  2. Performance Overhead Disable Rollbar in development to avoid unnecessary network calls:

    ddsimeonov_rollbar:
        enabled: '%kernel.debug% ? false : true%'
    
  3. Deprecated Symfony Versions The bundle supports Symfony 5+, but forks may be needed for older versions (e.g., Symfony 4). Check the symfony_3_4 branch if required.

  4. Rate Limiting Rollbar has rate limits. Monitor your error volume to avoid throttling.


Debugging

  • Verify Configuration Check if the bundle is loaded:

    php bin/console debug:config ddsimeonov_rollbar
    

    Should return your configured settings.

  • Test Locally Use a dummy token in .env to test without hitting production Rollbar:

    ROLLBAR_ACCESS_TOKEN=dummy_token_123
    
  • Check Logs Enable debug mode to see Rollbar-related logs:

    php bin/console debug:config monolog
    

    Look for rollbar handler entries.


Extension Points

  1. Custom Error Levels Extend the bundle to support custom Rollbar levels (e.g., warning):

    // src/Service/RollbarClient.php
    public function warning($message, array $data = []) {
        $this->client->log('warning', $message, $data);
    }
    
  2. Pre-Processing Payloads Override the RollbarClient service to modify payloads before sending:

    # config/services.yaml
    Ddsimeonov\RollbarBundle\RollbarClient:
        arguments:
            $client: '@your_custom_rollbar_client'
    
  3. Async Reporting Use Symfony Messenger to queue Rollbar reports for async processing:

    $message = new RollbarReportMessage($exception, $context);
    $this->messageBus->dispatch($message);
    
  4. Fork Maintenance If Rollbar archives the repo, fork and update dependencies:

    composer require symfony/*:^6.0 --dev
    composer update
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware