Skip to content

Commit

Permalink
⬆️ Upgrade sentry and improve its reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Oct 7, 2023
1 parent 15823df commit 3e7b9b3
Show file tree
Hide file tree
Showing 23 changed files with 1,931 additions and 1,726 deletions.
44 changes: 28 additions & 16 deletions apps/builder/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,32 @@ const nextConfig = {
},
}

const sentryWebpackPluginOptions = {
silent: true,
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA + '-builder',
}
export default withSentryConfig(
nextConfig,
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

export default process.env.NEXT_PUBLIC_SENTRY_DSN
? withSentryConfig(
{
...nextConfig,
sentry: {
hideSourceMaps: true,
widenClientFileUpload: true,
},
},
sentryWebpackPluginOptions
)
: nextConfig
// Suppresses source map uploading logs during build
silent: true,
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA + '-builder',
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: '/monitoring',

// Hides source maps from generated client bundles
hideSourceMaps: true,

// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
}
)
10 changes: 5 additions & 5 deletions apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"@giphy/react-components": "7.1.0",
"@googleapis/drive": "8.0.0",
"@paralleldrive/cuid2": "2.2.1",
"@sentry/nextjs": "7.66.0",
"@sentry/nextjs": "7.73.0",
"@tanstack/react-query": "^4.29.19",
"@tanstack/react-table": "8.9.3",
"@trpc/client": "10.34.0",
"@trpc/next": "10.34.0",
"@trpc/react-query": "10.34.0",
"@trpc/server": "10.34.0",
"@trpc/client": "10.40.0",
"@trpc/next": "10.40.0",
"@trpc/react-query": "10.40.0",
"@trpc/server": "10.40.0",
"@typebot.io/bot-engine": "workspace:*",
"@typebot.io/emails": "workspace:*",
"@typebot.io/env": "workspace:*",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as Sentry from '@sentry/nextjs'
import prisma from '@typebot.io/lib/prisma'

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA + '-builder',
integrations: [
new Sentry.Integrations.Prisma({
client: prisma,
}),
],
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prisma from '@typebot.io/lib/prisma'
import { authOptions } from '@/pages/api/auth/[...nextauth]'
import { setUser } from '@sentry/nextjs'
import * as Sentry from '@sentry/nextjs'
import { User } from '@typebot.io/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getServerSession } from 'next-auth'
Expand All @@ -19,7 +19,7 @@ export const getAuthenticatedUser = async (
| User
| undefined)
if (!user || !('id' in user)) return
setUser({ id: user.id })
Sentry.setUser({ id: user.id })
return user
}

Expand All @@ -30,7 +30,7 @@ const authenticateByToken = async (
const user = (await prisma.user.findFirst({
where: { apiTokens: { some: { token: apiToken } } },
})) as User
setUser({ id: user.id })
Sentry.setUser({ id: user.id })
return user
}

Expand Down
13 changes: 11 additions & 2 deletions apps/builder/src/helpers/server/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import { TRPCError, initTRPC } from '@trpc/server'
import { Context } from './context'
import { OpenApiMeta } from 'trpc-openapi'
import superjson from 'superjson'
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 isAuthed = t.middleware(({ next, ctx }) => {
if (!ctx.user?.id) {
throw new TRPCError({
Expand All @@ -20,10 +27,12 @@ const isAuthed = t.middleware(({ next, ctx }) => {
})
})

const finalMiddleware = sentryMiddleware.unstable_pipe(isAuthed)

export const middleware = t.middleware

export const router = t.router

export const publicProcedure = t.procedure
export const publicProcedure = t.procedure.use(sentryMiddleware)

export const authenticatedProcedure = t.procedure.use(isAuthed)
export const authenticatedProcedure = t.procedure.use(finalMiddleware)
9 changes: 9 additions & 0 deletions apps/builder/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Ratelimit } from '@upstash/ratelimit'
import { Redis } from '@upstash/redis/nodejs'
import got from 'got'
import { env } from '@typebot.io/env'
import * as Sentry from '@sentry/nextjs'

const providers: Provider[] = []

Expand Down Expand Up @@ -134,6 +135,14 @@ export const authOptions: AuthOptions = {
signIn: '/signin',
newUser: env.NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID ? '/onboarding' : undefined,
},
events: {
signIn({ user }) {
Sentry.setUser({ id: user.id })
},
signOut() {
Sentry.setUser(null)
},
},
callbacks: {
session: async ({ session, user }) => {
const userFromDb = user as User
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/src/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createContext } from '@/helpers/server/context'
import { trpcRouter } from '@/helpers/server/routers/v1/trpcRouter'
import { captureException } from '@sentry/nextjs'
import * as Sentry from '@sentry/nextjs'
import { createNextApiHandler } from '@trpc/server/adapters/next'

export default createNextApiHandler({
router: trpcRouter,
createContext,
onError({ error }) {
if (error.code === 'INTERNAL_SERVER_ERROR') {
captureException(error)
Sentry.captureException(error)
console.error('Something went wrong', error)
}
return error
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/src/pages/api/v1/[...trpc].ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext } from '@/helpers/server/context'
import { trpcRouter } from '@/helpers/server/routers/v1/trpcRouter'
import { captureException } from '@sentry/nextjs'
import * as Sentry from '@sentry/nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
import { createOpenApiNextHandler } from 'trpc-openapi'
import cors from 'nextjs-cors'
Expand All @@ -15,7 +15,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)
}
},
Expand Down
44 changes: 28 additions & 16 deletions apps/viewer/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,32 @@ const nextConfig = {
},
}

const sentryWebpackPluginOptions = {
silent: true,
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA + '-viewer',
}
export default withSentryConfig(
nextConfig,
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

// Suppresses source map uploading logs during build
silent: true,
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA + '-viewer',
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: '/monitoring',

// Hides source maps from generated client bundles
hideSourceMaps: true,

export default process.env.NEXT_PUBLIC_SENTRY_DSN
? withSentryConfig(
{
...nextConfig,
sentry: {
hideSourceMaps: true,
widenClientFileUpload: true,
},
},
sentryWebpackPluginOptions
)
: nextConfig
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
}
)
4 changes: 2 additions & 2 deletions apps/viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"dependencies": {
"@planetscale/database": "^1.8.0",
"@sentry/nextjs": "7.66.0",
"@trpc/server": "10.34.0",
"@sentry/nextjs": "7.73.0",
"@trpc/server": "10.40.0",
"@typebot.io/bot-engine": "workspace:*",
"@typebot.io/nextjs": "workspace:*",
"@typebot.io/prisma": "workspace:*",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as Sentry from '@sentry/nextjs'
import prisma from '@typebot.io/lib/prisma'

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA + '-viewer',
integrations: [
new Sentry.Integrations.Prisma({
client: prisma,
}),
],
})
11 changes: 10 additions & 1 deletion apps/viewer/src/helpers/server/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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)
4 changes: 2 additions & 2 deletions apps/viewer/src/pages/api/v1/[...trpc].ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
},
Expand Down
4 changes: 2 additions & 2 deletions apps/viewer/src/pages/api/v2/[...trpc].ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
},
Expand Down
11 changes: 2 additions & 9 deletions apps/viewer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": [
"src/*"
]
"@/*": ["src/*"]
},
"plugins": [
{
Expand All @@ -14,10 +12,5 @@
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
]
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"]
}
4 changes: 2 additions & 2 deletions packages/bot-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"dependencies": {
"@paralleldrive/cuid2": "2.2.1",
"@planetscale/database": "^1.8.0",
"@sentry/nextjs": "7.66.0",
"@trpc/server": "10.34.0",
"@sentry/nextjs": "7.73.0",
"@trpc/server": "10.40.0",
"@typebot.io/emails": "workspace:*",
"@typebot.io/env": "workspace:*",
"@typebot.io/lib": "workspace:*",
Expand Down
Loading

4 comments on commit 3e7b9b3

@vercel
Copy link

@vercel vercel bot commented on 3e7b9b3 Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 3e7b9b3 Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs.typebot.io
docs-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 3e7b9b3 Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

an.nigerias.io
app.yvon.earth
ar.nigerias.io
bot.enreso.org
bot.mail2wa.me
bot.rslabs.pro
bot.share5.net
bots.bng.tools
bots.bridge.ai
chad.gocto.com
chat.hayuri.id
chat.uprize.hu
chatgpt.lam.ee
chicken.cr8.ai
demo.bot.gives
drayumi.social
gollum.riku.ai
gsbulletin.com
journey.cr8.ai
kopibayane.com
panther.cr7.ai
panther.cr8.ai
pay.sifuim.com
penguin.cr8.ai
privetvplus.me
segredomeu.com
semaknilai.com
talk.gocare.io
ticketfute.com
unicorn.cr8.ai
whats-app.chat
whatsnaweb.com
apo.nigerias.io
app.blogely.com
apr.nigerias.io
aso.nigerias.io
blackcan.cr8.ai
blackvip.online
bot.4display.nl
bot.a6t-you.com
bot.artiweb.app
bot.devitus.com
bot.reeplai.com
bot.scayver.com
bot.tc-mail.com
carspecs.lam.ee
chat.borang.net
chat.lalmon.com
83242573.actualizar.xyz
87656003.actualizar.xyz
88152257.actualizar.xyz
91375310.actualizar.xyz
app.youvisitedthis.site
arrivalx2.wpwakanda.com
autopilot.autoforce.com
bot.blackboxtips.com.br
bot.chat-digital.online
bot.gamefantastico.club
bot.gameincrivel.online
bot.jogonobrasil.online
bot.jogoquelucra.online
bot.jogotecnologico.com
bot.ultimatecamp.com.br
chat.bebesemcolicas.com
viewer-v2-typebot-io.vercel.app
mdb.evento.autocadastro.progenbr.com
form.shopmercedesbenzsouthorlando.com
mdb.evento.equipeinterna.progenbr.com
bot.studiotecnicoimmobiliaremerelli.it
mdb.assessoria.boaventura.progenbr.com
mdb.assessoria.jtrebesqui.progenbr.com
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
mdb.assessoria.carreirinha.progenbr.com
chrome-os-inquiry-system.itschromeos.com
mdb.assessoria.paulomarques.progenbr.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
mdb.assessoria.qrcode.ademir.progenbr.com
mdb.assessoria.qrcode.arthur.progenbr.com
mdb.assessoria.qrcode.danilo.progenbr.com
mdb.assessoria.qrcode.marcao.progenbr.com
mdb.assessoria.qrcode.marcio.progenbr.com
mdb.assessoria.qrcode.aloisio.progenbr.com
mdb.assessoria.qrcode.girotto.progenbr.com
mdb.assessoria.qrcode.marinho.progenbr.com
mdb.assessoria.qrcode.rodrigo.progenbr.com
mdb.assessoria.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.desideri.progenbr.com
mdb.assessoria.qrcode.fernanda.progenbr.com
mdb.assessoria.qrcode.jbatista.progenbr.com
mdb.assessoria.qrcode.mauricio.progenbr.com
mdb.assessoria.fernanda.regional.progenbr.com
mdb.assessoria.qrcode.boaventura.progenbr.com
mdb.assessoria.qrcode.jtrebesqui.progenbr.com
mdb.assessoria.qrcode.carreirinha.progenbr.com
mdb.assessoria.qrcode.paulomarques.progenbr.com
mdb.assessoria.qrcode.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.fernanda.regional.progenbr.com

@vercel
Copy link

@vercel vercel bot commented on 3e7b9b3 Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.