-
Notifications
You must be signed in to change notification settings - Fork 341
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
Log outgoing HTTP requests when using HTTPoison.Base #302
Comments
You can probably achieve this by overriding def request(method, url, request_headers, body, hn_options) do
log_something(method, url, request_headers,body, hn_options)
super(method, url, request_headers, body, hn_options)
end |
Haha! My current workaround is almost exactly that: def request(method, url, headers, body, opts) do
super(method, url, headers, body, opts)
|> log_outgoing_http_request()
end |
I can keep using that approach as it works fine. Only real reason I brought it up was it feels a little awkward to shove a function in the middle of the request/response chain and hope it doesn't muck up the stack trace if anything goes wrong. Let me know if you ever think it would be anything useful. Otherwise, thanks for the quick reply/help. Thanks! |
I actually think this can be super useful. Let's wait for some feedback and see if more people like the idea? Thanks for starting this issue 👍 |
Logging a request would be really handy, especially when trying to debug. |
This would be really useful. Thanks @davidstump Couple suggestions for API:
That would leave the config API looking something like Happy to hear others' input and feedback. |
Thinking back about this - would it be easier/preferable for the lib to log the requests, or add another optional hook to handle/log responses allowing clients to log the data in whatever format, text, etc they want? |
I could see a case for going either way. On one side, keeping the library small keeps it simpler to maintain. Alternatively, helpful logging seems to fit well with the pit of success philosophy that is embraced elsewhere in the ecosystem. I lean slightly towards the latter, since I think that it's solid to have logging in place around IO in particular and that logs coming from the library would be particularly helpful for people who would probably plan to get around to doing it, but don't before they are having an issue. |
If you're running on top of hackney (I presume you are) there's a handy way to get detailed logging without polluting your code : https://github.com/benoitc/hackney/blob/master/doc/hackney_trace.md
I always forget this trick - maybe someone could PR it to the README or something. |
Just adding to @bryanhuntesl's post above, you can have it trace to stdout with
|
Howdy! First, thanks for the client - really enjoy using it :)
Second, I have had a few requests to log outgoing HTTP requests for a variety of reasons on different applications. When using your own methods that call out to something like
HTTPoison.get
- no big deal. However, when you are using the methoduse HTTPoison.Base
it becomes a bit harrier. You can use a few of the callbacks to log different parts of the requests, but this becomes a little cumbersome. Ideally, it would be nice to get a succinct log entry like:[info] [http] GET http://github.com/foo/bar STATUS 200
Would you be open to either a new extendable function that logs the current request, or an option passed to Base something like:
use HTTPoison.Base, log_requests: true
(or whatever naming sounds better than that)?Happy to work on a PR - but didn't know if there was any interest, opinions, etc first.
Cheers :)
The text was updated successfully, but these errors were encountered: