Get tRPC procedure latency?
Hi all, is there a supported mechanism to run common code to all procedures, say if I want to get latency metrics. I want to run the same latency math on all my procedures. I could create a helper function that I just have to remember to wrap all my procedure code in but just wondering if there's some supported tRPC way of doing this?
3 Replies
Solution
What about middleware
a middleware will only run before a procedure right?
When a middleware calls
opts.next()
that triggers the rest of the middleware chain and eventually the procedure. You can await it and track the runtime
(just make sure to return the result)