2
0

⬆️ Upgrade sentry and improve its reliability

This commit is contained in:
Baptiste Arnaud
2023-10-07 12:03:42 +02:00
parent 15823df6bd
commit 3e7b9b3afd
23 changed files with 1931 additions and 1726 deletions

View File

@@ -2,11 +2,18 @@ import { initTRPC } from '@trpc/server'
import { OpenApiMeta } from 'trpc-openapi'
import superjson from 'superjson'
import { Context } from './context'
import * as Sentry from '@sentry/nextjs'
const t = initTRPC.context<Context>().meta<OpenApiMeta>().create({
transformer: superjson,
})
const sentryMiddleware = t.middleware(
Sentry.Handlers.trpcMiddleware({
attachRpcInput: true,
})
)
const injectUser = t.middleware(({ next, ctx }) => {
return next({
ctx: {
@@ -15,8 +22,10 @@ const injectUser = t.middleware(({ next, ctx }) => {
})
})
const finalMiddleware = sentryMiddleware.unstable_pipe(injectUser)
export const middleware = t.middleware
export const router = t.router
export const publicProcedure = t.procedure.use(injectUser)
export const publicProcedure = t.procedure.use(finalMiddleware)

View File

@@ -1,5 +1,5 @@
import { appRouter } from '@/helpers/server/routers/appRouterV1'
import { captureException } from '@sentry/nextjs'
import * as Sentry from '@sentry/nextjs'
import { createOpenApiNextHandler } from 'trpc-openapi'
import cors from 'nextjs-cors'
import { NextApiRequest, NextApiResponse } from 'next'
@@ -13,7 +13,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
createContext,
onError({ error }) {
if (error.code === 'INTERNAL_SERVER_ERROR') {
captureException(error)
Sentry.captureException(error)
console.error('Something went wrong', error)
}
},

View File

@@ -1,5 +1,5 @@
import { appRouter } from '@/helpers/server/routers/appRouterV2'
import { captureException } from '@sentry/nextjs'
import * as Sentry from '@sentry/nextjs'
import { createOpenApiNextHandler } from 'trpc-openapi'
import cors from 'nextjs-cors'
import { NextApiRequest, NextApiResponse } from 'next'
@@ -13,7 +13,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
createContext,
onError({ error }) {
if (error.code === 'INTERNAL_SERVER_ERROR') {
captureException(error)
Sentry.captureException(error)
console.error('Something went wrong', error)
}
},