-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Request/Response timing #695
Comments
This could be written as a plugin. Something like: function axiosTiming(axiosInstance) {
// Store request timestamp in `config`
axiosInstance.interceptors.request.add(...);
// Store response timestamp and/or response time in response/error `config`
axiosInstance.interceptors.response.add(...);
} I'm not sure this feature is common enough to add it to the core (although it'd be relatively easy to implement and wouldn't have a performance penalty for those not using it). @mzabriskie, @nickuraltsev, thoughts? |
IMO, this would be great for debugging requests, more so on hybrid apps with less than ideal debugging environments. It would be a good addition to an already must-have like axios! Cheers. |
Hi, I am trying to implement this myself with the proposed approach with interceptors, but there are a few things I cannot figure out: I am not sure whether I can add random stuff to config (will it break axios, is there a right place for metadata), e.g:
|
Using the interceptors would provide a timing including the request and the parsing. That would be interesting to have a precise timing for the request itself. |
This would be a very useful feature, e.g. for instrumenting and monitoring 3rd party API performance. Ideally, to be compatible with |
You would end up with this subset:
|
Proof of concept for node, as a plugin / interceptors: https://gist.github.com/forivall/cbd363792b5e09c8aa4e8cb5390f8d93 hooks would need to be added for XHR timings. |
@forivall, thanks for providing this POC code! Here's some rough steps on how I was able to use it: Download and unpack .zip of cbd363792b5e09c8aa4e8cb5390f8d93 gist Copy resulting axios-timing.js into your project const addAxiosTiming = require('./axios-timing').addAxiosTiming; timings data will be available on the response |
I tried axios-timing.js but looking under the hood it basically uses interceptors. The problem with interceptors are they are called before the 'socket' event gets triggered on the http object (probably for good reason i suppose...). 100% I agree with @dev101 suggestion. |
here is the demo https://stackoverflow.com/a/62257712/8079868 |
Closing this issue as I don't think it will be added to the axios core. If you disagree please re-open |
I disagree, this should be added to the core |
I think this should be included in the core as an opt-in feature |
In my use case, a large blob is sent to a third-party service and processed before a response is sent. I would like to measure the time between finishing sending the data and the response. This would allow me to differentiate between slow upload (which may be down to network congestion) and slow processing. |
so? any updates here ... becauce any solution based on interseptors gives wrong data in browser((( |
It would be nice to have a metadata block returned in the response that would include a response time in milliseconds. I find myself having to write a small wrapper around axios to time any requests I make (for metric collection). Would this be a valid candidate for axios?
The text was updated successfully, but these errors were encountered: