Skip to main content

Symfony Messenger failures with their stack trace

Install sentry/sentry-symfony, turn it on for dev, and set SENTRY_DSN=http://sentry@127.0.0.1:8000/1. When a Messenger handler throws in your worker, the exception shows up in Buggregator with its stack trace. It sits next to your web errors and carries the message class as a tag.

Steps

1. Start Buggregator

bash
docker run --pull always \
  -p 127.0.0.1:8000:8000 \
  ghcr.io/buggregator/server:latest

2. Install the SDK and turn it on for dev

The recipe turns Sentry on for prod only. In config/bundles.php, turn the bundle on for dev too.

bash
composer require sentry/sentry-symfony
php
Sentry\SentryBundle\SentryBundle::class => ['dev' => true, 'prod' => true],

3. Point it at Buggregator

In config/packages/sentry.yaml, add a when@dev: block. The Messenger integration is on by default when Messenger is installed; the lines below only make it visible.

yaml
when@dev:
    sentry:
        dsn: '%env(SENTRY_DSN)%'
        messenger:
            enabled: true
            capture_soft_fails: true
dotenv
# .env.local
SENTRY_DSN=http://sentry@127.0.0.1:8000/1

In Docker Compose, use the Buggregator service name instead of 127.0.0.1.

4. Run the worker and fail a message

Start the worker for your transport, for example async, and dispatch a message whose handler throws.

bash
bin/console messenger:consume async -vv

5. Read the error

Open http://127.0.0.1:8000. The error shows the exception your handler threw, not the wrapper around it, with the stack trace. Its tags include messenger.message_class and messenger.receiver_name. A failure that will be retried is reported too, marked as handled. Set capture_soft_fails: false to see only the last failure.

Why it works

sentry-symfony listens for Messenger's failed-message event in the worker. It unwraps the handler's exception, adds the message tags and sends each exception at once, so a long-running worker does not hold errors back. Buggregator speaks the Sentry protocol, so the DSN is the only thing that points elsewhere.

Checked on with Buggregator v2.13.0

Setup in 60 seconds

No registration. No account. Start it and point your app at it.

1

Start Buggregator

One file, installed with one command. The web UI opens on port 8000. Prefer containers? Use the Docker tab.

$ curl -fsSL https://raw.githubusercontent.com/buggregator/server/master/scripts/install.sh | sh
$ HTTP_ADDR=127.0.0.1:8000 \
  SMTP_ADDR=127.0.0.1:1025 \
  VAR_DUMPER_ADDR=127.0.0.1:9912 \
  MONOLOG_ADDR=127.0.0.1:9913 \
  PROXY_ADDR=127.0.0.1:8080 \
  ~/.local/bin/buggregator

The script picks the file for your CPU: Intel/AMD or ARM.

One file for Linux, macOS and Windows, about 40 MB. Nothing else to install.

This run line keeps it on this computer. Without the *_ADDR settings it listens on all network interfaces

Rather not run a script? Download the file yourself

Runs on Windows, macOS and Linux, on Intel/AMD and ARM.

Prefer not to do it yourself? Your AI agent can set Buggregator up for you