import * as Sentry from "@sentry/nextjs" import { middleware } from "../../." import { flattenInput } from "./flattenInput" export const durationMiddleware = middleware( async ({ path, type, next, getRawInput }) => { const perf = performance.now() const res = await next() const duration = performance.now() - perf const input = await getRawInput() const primitiveInput = flattenInput(input) Sentry.metrics.distribution("all-trpc", duration, { unit: "milliseconds", attributes: { path, type, status: res.ok ? "ok" : "error", error: res.ok ? undefined : res.error.code, ...primitiveInput, }, }) return res } )