Adds perf metrics for each tRPC endpoint
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user