ddsimeonov/rollbar-php-symfony-bundle
Install the Bundle
composer require ddsimeonov/rollbar-php-symfony-bundle
Ensure your composer.json includes "symfony/framework-bundle": "^5.0" or higher.
Configure the Bundle
Add to config/bundles.php:
return [
// ...
Ddsimeonov\RollbarBundle\DdsimeonovRollbarBundle::class => ['all' => true],
];
Environment Configuration
Add Rollbar credentials to .env:
ROLLBAR_ACCESS_TOKEN=your_access_token_here
ROLLBAR_ENVIRONMENT=production|staging|development
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.
config/packages/ddsimeonov_rollbar.yaml (auto-generated after installation).src/EventListener/RollbarListener.php for custom logic hooks.Automatic Error Capture The bundle auto-captures:
ExceptionListener).Monolog integration).Example: No manual code changes needed for most exceptions.
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']
]);
}
}
CLI Error Tracking Errors in console commands are automatically captured. Example:
php bin/console your:command --with-errors
Contextual Data Attach metadata to errors:
$rollbar->info('User login', [
'user' => $user->toArray(),
'request' => $request->toArray()
]);
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
Sensitive Data Leakage
Avoid logging passwords, tokens, or PII. Use sanitize():
$rollbar->error('Failed payment', [
'card' => $request->request->get('card_number', '')->sanitize()
]);
Performance Overhead Disable Rollbar in development to avoid unnecessary network calls:
ddsimeonov_rollbar:
enabled: '%kernel.debug% ? false : true%'
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.
Rate Limiting Rollbar has rate limits. Monitor your error volume to avoid throttling.
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.
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);
}
Pre-Processing Payloads
Override the RollbarClient service to modify payloads before sending:
# config/services.yaml
Ddsimeonov\RollbarBundle\RollbarClient:
arguments:
$client: '@your_custom_rollbar_client'
Async Reporting Use Symfony Messenger to queue Rollbar reports for async processing:
$message = new RollbarReportMessage($exception, $context);
$this->messageBus->dispatch($message);
Fork Maintenance If Rollbar archives the repo, fork and update dependencies:
composer require symfony/*:^6.0 --dev
composer update
How can I help you explore Laravel packages today?