Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Messenger] add missing log context when sending to failure transport#46450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
ajardin wants to merge1 commit intosymfony:6.2fromajardin:messenger-logs

Conversation

@ajardin
Copy link
Contributor

@ajardinajardin commentedMay 24, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
TicketsN/A
LicenseMIT
Doc PRN/A

Why?

Logs generated bySendFailedMessageToFailureTransportListener::onMessageFailed do not include the message in the context, unlike those generated bySendFailedMessageForRetryListener::onMessageFailed.

Before

INFO      [messenger] Rejected message App\Message\MyCustomMessage will be sent to the failure transport Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport. [   "class" => "App\Message\MyCustomMessage",   "transport" => "Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport" ] [   "request_id" => false,   "uid" => "537143b" ]

After

INFO      [messenger] Rejected message App\Message\MyCustomMessage will be sent to the failure transport Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport. [   "message" => App\Message\MyCustomMessage {     -foo: true     -bar: false   },   "class" => "App\Message\MyCustomMessage",   "transport" => "Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport" ] [   "request_id" => false,   "uid" => "537143b" ]

duboiss reacted with thumbs up emojimaxhelias reacted with eyes emoji
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@chalasr
Copy link
Member

Thanks for the PR. This change looks like a new feature to me, or is there something that breaks without it?

@ajardin
Copy link
ContributorAuthor

Hello and thanks for the reply! 🙂

You're right, it's notbroken. I was also hesitating between a bug and a feature...
Basically, it makes the log less useful as the relationship between the message and the event is not visible, which makes me think it's amissing element rather than anew. What do you think?

@fabpot
Copy link
Member

That’s a new feature 😀

ajardin reacted with thumbs up emoji

@ajardinajardin changed the base branch from4.4 to6.1May 25, 2022 10:05
@chalasrchalasr modified the milestones:4.4,6.2May 25, 2022
@chalasrchalasr changed the base branch from6.1 to6.2May 25, 2022 10:07
@ajardin
Copy link
ContributorAuthor

I have updated the pull request accordingly. 😉

@lyrixx
Copy link
Member

lyrixx commentedMay 25, 2022
edited
Loading

Message content can be very huge. This can also overflow some third party service.

But I like the idea. I'm my application, I usually log raw object, then I add a custom monolog processor to keep only what I need. (I gave atalk about it)

We could do the same here

  1. Log with the raw envelop
  2. Add a default monolog processor that
    • Remove eveything and keep only the class.
    • Or keep only the 1024 first bytes of the content (arbitrary number)

So if people want more or less information in the log, they can decorate / replace the default processor in the DIC.


WDYT?

(I actually really like the idea. I think it could be generalized to the framework, when applicable)

ajardin reacted with thumbs up emoji

@ajardin
Copy link
ContributorAuthor

Your idea goes further than my initial thoughts, but I really like it! 🙂

Instead of adding an additional risk of overflow (the message is already logged in multiple places), we would fix a minor lack and improve the component monitoring. Moreover, the possibility to replace/decorate the processor would be great.

I can try to work on this approach in the coming days if nobody else is on it.
In the meantime, what do you want to do with this pull request?

@lyrixx
Copy link
Member

I can try to work on this approach in the coming days if nobody else is on it.

Please, wait for more approval from the core team, I'm not sure everything is OK with that

ping @symfony/mergers

Copy link
Member

@NyholmNyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I agree with@lyrixx. This is a great feature. But messages can be huge. Messages can also include sensitive data (passwords) that should not end up in the logs.

I suggest to remove themessage. Adding the message class is little but enough info to add more logging in your app if you need to know the exact contents of the message.

$message =$envelope->getMessage();
$this->logger?->info('Rejected message {class} will be sent to the failure transport {transport}.', [
'class' =>\get_class($envelope->getMessage()),
'message' =>$message,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I suggest ro remove this key.

$this->logger?->info('Rejected message {class} will be sent to the failure transport {transport}.', [
'class' =>\get_class($envelope->getMessage()),
'message' =>$message,
'class' =>\get_class($message),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
'class' =>\get_class($message),
'message_class' =>\get_class($message),

@ajardin
Copy link
ContributorAuthor

@Nyholm removing this key is basically closing the pull request. 😅

Joke aside, what is your opinion on the processor approach proposed by@lyrixx? We could only keep the message class by default and let users decide if they want to add further data through decorators.

Because even if we decide to not add the message withinSendFailedMessageToFailureTransportListener::onMessageFailed logs, the message is already available (at least) in:

  • \Symfony\Component\Messenger\TraceableMessageBus::dispatch
  • \Symfony\Component\Messenger\Worker::ack
  • \Symfony\Component\Messenger\EventListener\SendFailedMessageForRetryListener::onMessageFailed
  • \Symfony\Component\Messenger\Middleware\HandleMessageMiddleware::handle
  • \Symfony\Component\Messenger\Middleware\SendMessageMiddleware::handle

@ajardin
Copy link
ContributorAuthor

Hello@lyrixx and@Nyholm,

Did you have the opportunity to discuss the changes mentioned above? Thanks for your time.

@lyrixx
Copy link
Member

Adding the raw message is a no go unfortunately. IMHO the custom processor is the way to go.

@ajardin
Copy link
ContributorAuthor

Thanks for your feedback. In that case, I'm closing this pull request.

But while I understand the reason why adding the message could cause problems (e.g. leak of sensitive data or logs overflow), I don't understand why it's a problem here and not in the other parts of the component. Am I missing something?

@Nyholm
Copy link
Member

You are correct. Maybe we did miss something in previous prs.

I would be super happy if you want to help by removing those instances to.
I definitely understand if you don’t, but please tell us so someone else can work on that.

@ajardin
Copy link
ContributorAuthor

No problem, I'll submit a PR with the removal of other instances.

But I would love to have a workaround idea for the application I'm working on since we use the message details to monitor exactly what's going on. 😉

Should we subscribe to Messenger events and add our own log entries?

Nyholm reacted with heart emoji

@Nyholm
Copy link
Member

Should we subscribe to Messenger events and add our own log entries?

Yes,
You can also add your custom middleware. That will give you maximum control.

fabpot added a commit that referenced this pull requestJun 25, 2022
This PR was merged into the 5.4 branch.Discussion----------[Messenger] Do not log the message object itselfIn order to avoid the leak of sensitive data (e.g. credentials) or the overflow of third-party services.| Q             | A| ------------- | ---| Branch?       | 5.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       || License       | MIT| Doc PR        |This is a follow-up of#46450 where we had a discussion with@Nyholm about the problems related to the logging of the message object. I'm targeting the `5.4` branch as we see this change as a (security ?) fix rather than a new feature.Commits-------f1604e6 [Messenger] Do not log the message object itself
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@NyholmNyholmNyholm requested changes

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@wouterjwouterjAwaiting requested review from wouterj

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

6 participants

@ajardin@carsonbot@chalasr@fabpot@lyrixx@Nyholm

[8]ページ先頭

©2009-2025 Movatter.jp