Replies: 1 comment
-
You can track flight times outside of the middleware. I haven't tried this at run-time, but I think a simple Map may do the trick, without affecting any of the middleware signatures. const requestStartTimes: Map<Request, number> = new Map();
const myMiddleware: Middleware = {
async onRequest({ request }) {
requestStartTimes.set(request, performance.now());
},
async onResponse({ request }) {
const startTime = requestStartTimes.get(request);
requestStartTimes.delete(request);
const endTime = performance.now();
const latency = endTime - startTime;
console.log(latency);
},
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
I'm looking to use middleware to measure the request time of
openapi-fetch
client requests - what's a good way to achieve this? The objects available inopenapi-fetch
middleware don't appear to include request time.One approach I've considered is attaching the request start time to the
Request
object whenonRequest
is triggered, and then calculating the request time in theonResponse
hook e.g.This requires working around the types somewhat though.
Are there any other approaches I could consider?
Proposal
N/A
Extra
Beta Was this translation helpful? Give feedback.
All reactions