Merged in chore/upgrade-sentry (pull request #3191)
feat: upgrade sentry and use metrics * feat: upgrade sentry and use metrics * remove ununsed deps * rename span * . Approved-by: Linus Flood
This commit is contained in:
28
packages/trpc/lib/middlewares/durationMiddleware/index.ts
Normal file
28
packages/trpc/lib/middlewares/durationMiddleware/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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("trpc", duration, {
|
||||
unit: "milliseconds",
|
||||
attributes: {
|
||||
path,
|
||||
type,
|
||||
status: res.ok ? "ok" : "error",
|
||||
error: res.ok ? undefined : res.error.code,
|
||||
...primitiveInput,
|
||||
},
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user