Adds perf metrics for each tRPC endpoint

This commit is contained in:
zomars
2022-06-27 19:19:33 -06:00
parent 2ba8f99302
commit 87befdbdf4
3 changed files with 14 additions and 3 deletions
+9 -1
View File
@@ -1,3 +1,5 @@
import { performance } from "@calcom/lib/server/perfObserver";
import * as trpc from "@trpc/server";
import { Context } from "./createContext";
@@ -6,7 +8,13 @@ import { Context } from "./createContext";
* Helper function to create a router with context
*/
export function createRouter() {
return trpc.router<Context>();
return trpc.router<Context>().middleware(async ({ path, type, next }) => {
performance.mark("Start");
const result = await next();
performance.mark("End");
performance.measure(`[${result.ok ? "OK" : "ERROR"}][$1] ${type} '${path}'`, "Start", "End");
return result;
});
}
export function createProtectedRouter() {