Skip to content

Structured logs leak across Messenger messages causing unrelated logs to be attached to errors #970

@Gregory-Gerard

Description

@Gregory-Gerard

How do you use Sentry?

Sentry SaaS (sentry.io)

SDK version

  • sentry/sentry: 4.17.1
  • sentry/sentry-symfony: 5.6.0

Description

Similar to the breadcrumb leak issue fixed in #946, the new Sentry Logging feature (structured logs) exhibits the same behavior where logs are not properly isolated between Messenger messages. When an error occurs in a message handler, the associated logs include all logs from the entire worker lifecycle, including logs from other messages, Messenger startup/shutdown, and unrelated errors.

Steps to reproduce

  1. Set up a Symfony application with:

    • Sentry PHP SDK with Logging feature enabled (enable_logs: true)
    • Sentry Symfony Bundle
    • Monolog configured with Sentry\Monolog\LogsHandler
    • Symfony Messenger with async messages
  2. Configure the Messenger worker to process multiple messages

  3. Create multiple message handlers that:

    • Log information during processing
    • One of them throws an exception
  4. Run the Messenger worker and process several messages sequentially

  5. Check the Sentry event for the failed message

Expected result

The Sentry error event should contain only logs related to the specific failed message, similar to how breadcrumbs are isolated when isolate_breadcrumbs_by_message: true is configured.

Actual result

The Sentry error event contains all logs from the entire worker session, including:

  • Logs from other successfully processed messages
  • Logs from other failed messages
  • Messenger worker startup/shutdown logs
  • All logs accumulated since the worker started
Image

You can see that I receive the logs on the same trace when I close the Symfony Messenger worker 10 minutes later. You can also see the logs for the other messages, including the message with retry.


Thank you for your time. I am willing to investigate further if necessary 😉

Metadata

Metadata

Assignees

Labels

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions