sentry-symfony icon indicating copy to clipboard operation
sentry-symfony copied to clipboard

Console commands are missing breadcrumbs and context with BreadcrumbHandler

Open Dukecz opened this issue 2 years ago • 1 comments

How do you use Sentry?

Self-hosted / on-premises

SDK version

3.5.0

Steps to reproduce

I have prepared minimal symfony project with sentry integration: https://github.com/Dukecz/sentrysymfonycommand

  1. clone repository
  2. set ENV variable SENTRY_DSN
  3. run composer install
  4. run php bin/console app:test

Expected result

Sentry should contain all logged events (https://github.com/Dukecz/sentrysymfonycommand/blob/master/src/Command/TestCommand.php) in breadcrumbs with context as it does when they are logged outside command.

image

Actual result

Sentry contains no breadcrumbs generated within command scope.

image

If I commented out $this->hub->popScope() in \Sentry\SentryBundle\EventListener\ConsoleListener::handleConsoleTerminateEvent , breadcrumbs got into Sentry

Dukecz avatar Sep 19 '23 16:09 Dukecz

Update for 4.1.0:

Context and some breadcrumbs are now showing in Sentry (24.9.0) but still missing previous info/warning messages:

Image

Dukecz avatar Jan 15 '25 15:01 Dukecz

Hi @Dukecz! I looked at this and your other issue and I believe my PR fixes both of them.

The problem was that the monolog buffers were flushed too late and we processed Symfony events before flushing, which removed data through things like popScope. My change introduces handler that flush on certain events to populate events with proper information.

Litarnus avatar Aug 12 '25 13:08 Litarnus