ferdy
ferdy2y ago

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?
Solution:
What about middleware
Jump to solution
3 Replies
Solution
backbone
backbone2y ago
What about middleware
ferdy
ferdyOP2y ago
a middleware will only run before a procedure right?
Nick
Nick2y ago
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)

Did you find this page helpful?