-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] Add debugData
property to SentMessage
class
#51746
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Notifier] Add debugData
property to SentMessage
class
#51746
Conversation
Not sure about this, I mean it makes sense to have more debug data available, but not sure about the method name and signature. WDYT @fabpot ? |
The response is already logged in the HttpClient i believe, no ? I see how this could be used, but maybe add a toggle/config to enable it only in debug mode ? Maybe i'm wrong, but i'm feeling a bit "afraid" of the added "weight" (messenger / serialization ..) |
Looking at the linked issue, this is not about debugging but rather about providing extra info. |
return $this->debugData; | ||
} | ||
|
||
public function setDebugData(array $data): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should instead be a new constructor argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose the setter method initially because some transporters may work differently and not have http-response or extra-data to include?
So, it would make sense to make it an optional same as setMessageId()
?
Not sure but just clarifying
@nicolas-grekas Nice, We can then ensure this via adding the whole response object? |
Having a free-form array where each transport can add anything looks like a bad idea. |
@nicolas-grekas what about something like this: diff --git a/src/Symfony/Component/Notifier/Message/SentMessage.php b/src/Symfony/Component/Notifier/Message/SentMessage.php
index 6febf9ebc9..bd662f68aa 100644
--- a/src/Symfony/Component/Notifier/Message/SentMessage.php
+++ b/src/Symfony/Component/Notifier/Message/SentMessage.php
@@ -19,6 +19,7 @@ class SentMessage
private MessageInterface $original;
private string $transport;
private ?string $messageId = null;
+ private array $info = [];
public function __construct(MessageInterface $original, string $transport)
{
@@ -45,4 +46,23 @@ class SentMessage
{
return $this->messageId;
}
+
+ public function setInfo(int $responseStatusCode, array $responseHeaders = [], array $body = []): void
+ {
+ $this->info = [
+ 'response' => [
+ 'status_code' => $responseStatusCode,
+ 'headers' => $responseHeaders,
+ 'body' => $body,
+ ]
+ ];
+ }
+
+ /**
+ * @return array{response: array{status_code: int, headers: array, body: array}
+ */
+ public function getInfo(): array
+ {
+ return $this->info;
+ }
} |
With some |
In HttpClient we documented the standard info keys, and decorators can add their own things there alsp (e.g. the number of retries for the RetryableHttpClient). This works well. What's the alternative? |
How can we move forward on that PR ? I think the @OskarStark solution is better than original. We don't want to put debug info but more info from return response if provided. Do you want me to make another PR with your solution directly ? Or could we update this one ? We've been waiting for this improvement for a long time now to pick the fees natively. Is the header is really necessary inside info (too much as @smnandre said) ? |
Closing as this PR won't be fixed as is. If someone wants to continue working on this, please open a new PR, maybe based on @OskarStark idea. |
This PR was merged into the 7.3 branch. Discussion ---------- [Notifier] Add SentMessage additional info | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #49793 | License | MIT This PR allows adding additional data into [Notifier/Message/SentMessage.php](https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/Notifier/Message/SentMessage.php), based on (and using) [HttpClient Response's info](https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpClient/Response/AsyncContext.php#L118-L145). The initial need behind this feature is to be able to access to some data of the Transport's response (e.g.: [`nbSms` and `cost` for allmysms](https://doc.allmysms.com/api/fr/#api-SMS-sendsimple), or [`totalCreditsRemoved` for OVH Cloud](https://eu.api.ovh.com/console/?section=%2Fsms&branch=v1#post-/sms/-serviceName-/jobs)). Original (closed) PR: #51746 Some points to discuss: - It would be a lot easier to inject the eventual `ResponseInterface` object into the constructor as a readonly property, but not all Transports are using HTTP - [Having a free-form array where each transport can add anything looks like a bad idea](#51746 (comment)), but [In HttpClient you documented the standard info keys, and decorators can add their own things there](#51746 (comment)) Commits ------- a50f38c feat(notifier): add SentMessage additional info
As stated in the title, adding such a property would allow transports to include additional information in the returned
SentMessage
object (e.g. http response)