sfertrack/rollbar-symfony-bundle
A Symfony bundle that integrates Rollbar error tracking, helping you capture and report exceptions and errors from your Symfony application to Rollbar through bundle configuration.
Install and register
composer require sfertrack/rollbar-symfony-bundle
For Symfony Flex apps the bundle should be auto-registered; otherwise add it manually in config/bundles.php:
Sfertrack\RollbarBundle\SfertrackRollbarBundle::class => ['all' => true],
Find the config surface first. Before wiring anything, open the bundle's DependencyInjection/Configuration.php and its README. This package is a small, low-adoption fork (0 stars), so the canonical docs are the source tree rather than blog posts. Look for:
rollbar or sfertrack_rollbar),access_token, environment) versus optional (person_fn, scrub_fields, minimum_level).Minimum viable config (config/packages/rollbar.yaml):
rollbar:
access_token: '%env(ROLLBAR_ACCESS_TOKEN)%'
environment: '%env(ROLLBAR_ENV)%'
enabled: '%env(bool:ROLLBAR_ENABLED)%'
Set the env vars per environment: a post_server_item token for prod/staging, ROLLBAR_ENABLED=false in dev and test.
First use case: catch uncaught exceptions. In most setups the bundle hooks kernel.exception automatically. Validate it by throwing deliberately in a controller:
public function boom(): Response
{
throw new \RuntimeException('rollbar smoke test');
}
Then confirm the item appears in the Rollbar dashboard with the right environment, server.host, and code version. If nothing arrives, set enabled: true, run bin/console cache:clear, and check var/log/ for transport errors — this is the fastest way to distinguish a config problem from a network/token problem.
Second step: decide your entry point. You will almost always use one of three:
error-level logs),reportMessage/reportException calls.Pick (1) + (3) for typical apps; add (2) only if your logging discipline is already strong.
Monolog handoff for warnings and above. Route a channel to the bundle's handler so every error/critical log ships, without duplicating exception reporting.
monolog:
handlers:
rollbar:
type: service
id: rollbar.handler # confirm the real service ID in services.xml
level: error
bubble: true
Keep bubble: true so fingers_crossed/file handlers still receive the record.
Inject the reporter for explicit, contextual reports. Where you have rich domain context, report directly rather than relying on the exception listener:
final class PaymentService
{
public function __construct(private RollbarLogger $rollbar) {}
public function charge(Order $order): void
{
try {
// ...
} catch (GatewayException $e) {
$this->rollbar->reportException($e, [
'order_id' => $order->getId(),
'gateway' => 'stripe',
]);
throw $e;
}
}
}
Attach the user and request context once. If the bundle ships a person provider hook, use it; otherwise add a small listener on kernel.request that sets Rollbar::getNotifier()->addCustomData(...) or the equivalent — this makes every downstream item searchable by user ID.
#[AsEventListener(event: KernelEvents::REQUEST)]
final class RollbarContextListener
{
public function __invoke(RequestEvent $event): void
{
if (!$event->isMainRequest()) return;
$req = $event->getRequest();
Rollbar::addCustomData('route', $req->attributes->get('_route'));
Rollbar::addCustomData('request_id', $req->headers->get('X-Request-Id'));
}
}
Environment matrix. Treat Rollbar env as a first-class value, not a copy of APP_ENV:
# config/packages/prod/rollbar.yaml
rollbar:
enabled: true
environment: '%env(ROLLBAR_ENV)%' # e.g. "production-eu"
capture_email: false
scrub_fields: ['password', 'token', 'authorization', 'cookie']
Framework-agnostic exception listener alternative. If the built-in listener is too coarse, disable it (rollbar.capture_exceptions: false) and write your own kernel.exception subscriber so you control what gets reported versus what gets re-thrown/rendered as a 4xx.
Fingerprinting for sane grouping. Pass fingerprint in the custom payload for exceptions that are otherwise grouped into one bucket (e.g. a generic ValidationException). This is the single highest-leverage tuning for signal-to-noise.
CLI and Messenger. Web requests get context automatically; console and worker processes do not. Add rollbar.environment awareness and push the command name / message class as custom data from a ConsoleEvents::COMMAND listener or a Messenger middleware, otherwise all worker errors land as anonymous.
Test strategy. Disable the bundle in test (ROLLBAR_ENABLED=0) so the SDK never attempts network calls during the suite; if you must assert reporting, replace the reporter service with a spy in config/services_test.yaml.
DependencyInjection and handler code, and have an exit plan: the underlying rollbar/rollbar-php SDK plus a ~40-line Monolog handler and exception listener reproduces 90% of this bundle. Budget for that migration.error will often ship the same exception twice. Either drop Monolog error records to a lower level or disable automatic capture; check the resulting item counts in Rollbar for a week.read token will appear to work in config validation but produce no items.environment defaults are a trap. Many Rollbar integrations inherit APP_ENV; that splits your data into prod, production, and staging buckets the moment someone renames an env var. Set it explicitly in each config/packages/{env}/ file.minimum_level, captured_message_limit, and sampling/excluded exceptions before go-live. A noisy NotFoundHttpException or ConnectionException on a busy queue can burn a free-tier quota in a day.scrub_fields covers authorization, cookie, set-cookie, php-auth-pw, and any domain-specific secrets. The scrubber runs on serialized payloads — nested keys inside objects are not always caught, so avoid putting raw request bodies in custom data.rollbar.transport is set to the curl or a queued transport, the payload is serialized after the response; custom data registered in a kernel.terminate listener may be missing. Register context in kernel.request/kernel.exception instead.cache:clear, and after changing the env var you may need cache:clear --env=prod — a common "why is it disabled?" red herring.person provider (to inject your UserInterface) and the exception listener (to add ignored_exceptions). Both are small classes and low-risk to override via service decoration.enabled: true and the token format, then wrap a manual reportMessage('ping') in a controller; if that fails, the issue is transport/TLS (common behind corporate proxies or PHP builds without curl/openssl), not the bundle.messenger:consume, RoadRunner/Swoole), call Rollbar::flush() (or the bundle's equivalent) at the end of each message/request cycle, or you will lose the last batch on process restart.X-Request-Id (or Rollbar's own UUID) down to Twig and into the JS SDK so frontend and backend items share a trace — trivial once request_id is in custom data, and it's what makes this bundle actually pay for itself during incidents.How can I help you explore Laravel packages today?