I want to use a CF worker to intercept all requests to our REST API endpoint on Tallyfy and log the following to an external service:
- HTTP verb
- Source geo/country
- Time elapsed between request and response.
- User bearer token
- Payload, URL.
- … etc.
Does anyone have any sample code/approach to demonstrate the above being done after the initial request has been responded to? We want this to be non-blocking i.e. the original API request is served with no extra lag time, and after it’s been served, we then asynchronously log information about the call to an external logging service.
The important part is (3) - how can I actually measure the elapsed time to serve the request (to later do performance analytics in my API) accurately and properly?
From what I understand, promises are async, whereas in this case - we must wait for the full request to be ready to send back before attempting to log it.
Thanks for any help!