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

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

Open Gregory-Gerard opened this issue 1 month ago • 4 comments

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 😉

Gregory-Gerard avatar Nov 06 '25 13:11 Gregory-Gerard

SYMFONY-31

linear[bot] avatar Nov 06 '25 13:11 linear[bot]

Hi @Gregory-Gerard! Thanks for opening the issue and the very detailed explanation!

and unrelated errors.

Do you have more details here? From your screenshot it seems like all logs are somewhat related.

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.

I agree, we will look into adding this setting for logs too since both cases have their merits.

Litarnus avatar Nov 06 '25 13:11 Litarnus

Hi @Litarnus!

Thanks for your time reviewing this!

By "unrelated errors" I just meant logs that should be attached to other Sentry traces/events, not to this specific one.

What happens is: when message A fails and creates a Sentry event, the logs attached to that event include logs from message B, message C, etc. that were processed by the same worker. Those logs should have been attached to their respective Sentry events (if they created any), not all grouped together on message A's event. Sorry for the imprecise wording!

Let me know if you need more details, happy to provide additional information.

Gregory-Gerard avatar Nov 06 '25 13:11 Gregory-Gerard

Perfect, thank you for your explanation! I think that's all I need to start working on it

Litarnus avatar Nov 06 '25 14:11 Litarnus