-
Notifications
You must be signed in to change notification settings - Fork 850
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
Add support for HTTP request monitoring callback #764
Conversation
e324cef
to
5fc6d0c
Compare
ptal @rattrayalex-stripe |
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.
Slightly worried about users throwing from within the callback and blocking a retry intentionally or unintentionally, but I don't think it's worth losing sleep over
Doesn't seem like a fun usage from a client perspective knowing all network retry logic is on the Currently I have: Stripe::setApiKey('magic');
Stripe::$maxNetworkRetries = 3;
$paymentIntent = PaymentIntent::create($requestParams, $requestOptions); This is why my proposal was what it was in #763 to keep the pattern there. Thank you for quickly putting this up! |
That's a fair criticism. The max retries number should really be a property of |
Released as 7.4.0. |
As a user who alters the CurlClient.php source to add logging it's not quite there. I log the url +parameters of the api call and I don't see a way to do that. It would be nice if it also passed the $opts array. |
@jmraker Interesting use case! I think it might be more appropriate to have two callbacks: one before the request with the request properties (method, URL, parameters) and one after the request with the response properties (status code, response body, etc.). I don't want to rush into things though as I'm planning on some major changes to the HTTP client interface. In the meantime, I think a cleaner workaround that would not require you to modify the library's source code would be to subclass class LoggingCurlClient extends \Stripe\HttpClient\CurlClient
{
public function request($method, $absUrl, $headers, $params, $hasFile)
{
// log request parameters
list($rbody, $rcode, $rheaders) = parent::request($method, $absUrl, $headers, $params, $hasFile);
// log response parameters
return [$rbody, $rcode, $rheaders];
}
}
$loggingClient = new LoggingCurlClient();
\Stripe\ApiRequestor::setHttpClient($loggingClient); |
r? @rattrayalex-stripe
cc @stripe/api-libraries @suadhuskic
Add support for passing a callback that is called after every HTTP request. This can be used for logging, monitoring, stats, or anything else.
Used like this:
@suadhuskic This is a bit more complex than what you submitted but also more powerful, since it lets you access more information about the request (e.g. the HTTP status code, the request ID in the headers, etc.). I think it would also work for your use case, what do you think?