Skip to content

Commit

Permalink
build(viewer): πŸ—οΈ Add sentry to viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 15, 2022
1 parent ea80fd6 commit b339add
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 5 deletions.
1 change: 1 addition & 0 deletions apps/viewer/.env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ EMAIL_NOTIFICATIONS_SERVER_PORT=587
NEXT_PUBLIC_EMAIL_NOTIFICATIONS_FROM_EMAIL=noreply@example.com
NEXT_PUBLIC_EMAIL_NOTIFICATIONS_FROM_NAME="John Smith"

NEXT_PUBLIC_SENTRY_DSN=
27 changes: 27 additions & 0 deletions apps/viewer/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This file sets a custom webpack configuration to use your Next.js app
// with Sentry.
// https://nextjs.org/docs/api-reference/next.config.js/introduction
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { withSentryConfig } = require('@sentry/nextjs')

const moduleExports = {
// Your existing module.exports
}

const sentryWebpackPluginOptions = {
// Additional config options for the Sentry Webpack plugin. Keep in mind that
// the following options are set automatically, and overriding them is not
// recommended:
// release, url, org, project, authToken, configFile, stripPrefix,
// urlPrefix, include, ignore

silent: true, // Suppresses all logs
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options.
}

// Make sure adding Sentry options is the last code to run before exporting, to
// ensure that your source maps include changes from all other Webpack plugins
module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions)
1 change: 1 addition & 0 deletions apps/viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@sentry/nextjs": "^6.17.8",
"bot-engine": "*",
"cors": "^2.8.5",
"db": "*",
Expand Down
65 changes: 65 additions & 0 deletions apps/viewer/pages/_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import NextErrorComponent from 'next/error'

import * as Sentry from '@sentry/nextjs'

const MyError = ({ statusCode, hasGetInitialPropsRun, err }) => {
if (!hasGetInitialPropsRun && err) {
// getInitialProps is not called in case of
// https://github.com/vercel/next.js/issues/8592. As a workaround, we pass
// err via _app.js so it can be captured
Sentry.captureException(err)
// Flushing is not required in this case as it only happens on the client
}

return <NextErrorComponent statusCode={statusCode} />
}

MyError.getInitialProps = async (context) => {
const errorInitialProps = await NextErrorComponent.getInitialProps(context)

const { res, err, asPath } = context

// Workaround for https://github.com/vercel/next.js/issues/8592, mark when
// getInitialProps has run
errorInitialProps.hasGetInitialPropsRun = true

// Returning early because we don't want to log 404 errors to Sentry.
if (res?.statusCode === 404) {
return errorInitialProps
}

// Running on the server, the response object (`res`) is available.
//
// Next.js will pass an err on the server if a page's data fetching methods
// threw or returned a Promise that rejected
//
// Running on the client (browser), Next.js will provide an err if:
//
// - a page's `getInitialProps` threw or returned a Promise that rejected
// - an exception was thrown somewhere in the React lifecycle (render,
// componentDidMount, etc) that was caught by Next.js's React Error
// Boundary. Read more about what types of exceptions are caught by Error
// Boundaries: https://reactjs.org/docs/error-boundaries.html

if (err) {
Sentry.captureException(err)

// Flushing before returning is necessary if deploying to Vercel, see
// https://vercel.com/docs/platform/limits#streaming-responses
await Sentry.flush(2000)

return errorInitialProps
}

// If this point is reached, getInitialProps was called without any
// information about what the error might be. This is unexpected and may
// indicate a bug introduced in Next.js, so record it in Sentry
Sentry.captureException(
new Error(`_error.js getInitialProps missing data at path: ${asPath}`)
)
await Sentry.flush(2000)

return errorInitialProps
}

export default MyError
3 changes: 2 additions & 1 deletion apps/viewer/pages/api/answers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withSentry } from '@sentry/nextjs'
import { Answer } from 'db'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
Expand All @@ -22,4 +23,4 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return methodNotAllowed(res)
}

export default handler
export default withSentry(handler)
3 changes: 2 additions & 1 deletion apps/viewer/pages/api/integrations/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createTransport } from 'nodemailer'
import { decrypt, initMiddleware } from 'utils'

import Cors from 'cors'
import { withSentry } from '@sentry/nextjs'

const cors = initMiddleware(Cors())

Expand Down Expand Up @@ -74,4 +75,4 @@ const getEmailInfo = async (
return decrypt(credentials.data, credentials.iv) as SmtpCredentialsData
}

export default handler
export default withSentry(handler)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GoogleSpreadsheet } from 'google-spreadsheet'
import { getAuthenticatedGoogleClient } from 'libs/google-sheets'
import { Cell } from 'models'
import Cors from 'cors'
import { withSentry } from '@sentry/nextjs'

const cors = initMiddleware(Cors())
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
Expand Down Expand Up @@ -74,4 +75,4 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return methodNotAllowed(res)
}

export default handler
export default withSentry(handler)
3 changes: 2 additions & 1 deletion apps/viewer/pages/api/results.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withSentry } from '@sentry/nextjs'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'
Expand All @@ -13,4 +14,4 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return methodNotAllowed(res)
}

export default handler
export default withSentry(handler)
3 changes: 2 additions & 1 deletion apps/viewer/pages/api/results/[id].ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withSentry } from '@sentry/nextjs'
import prisma from 'libs/prisma'
import { Result } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
Expand All @@ -16,4 +17,4 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return methodNotAllowed(res)
}

export default handler
export default withSentry(handler)
15 changes: 15 additions & 0 deletions apps/viewer/sentry.client.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file configures the initialization of Sentry on the browser.
// The config you add here will be used whenever a page is visited.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs'

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
// ...
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
// that it will also get attached to your source maps
})
4 changes: 4 additions & 0 deletions apps/viewer/sentry.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaults.url=https://sentry.io/
defaults.org=typebot
defaults.project=viewer
cli.executable=../../../../.npm/_npx/14461/lib/node_modules/@sentry/wizard/node_modules/@sentry/cli/bin/sentry-cli
15 changes: 15 additions & 0 deletions apps/viewer/sentry.server.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs'

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
// ...
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
// that it will also get attached to your source maps
})
115 changes: 115 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3366,6 +3366,16 @@
"@sentry/utils" "6.17.7"
tslib "^1.9.3"

"@sentry/browser@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.17.8.tgz#de665c7abc257cab66e442e8113e9a9d610786b3"
integrity sha512-IvpcSja513PHySy1BhtE1K75kMzso4e4FWqZ2KgPLJacJdPMICNgjS+MwZ1g218m2JWkoQHOmWENBTqHaBHZ6g==
dependencies:
"@sentry/core" "6.17.8"
"@sentry/types" "6.17.8"
"@sentry/utils" "6.17.8"
tslib "^1.9.3"

"@sentry/cli@^1.72.0":
version "1.72.2"
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-1.72.2.tgz#ba57d8248fe4d2836883bbe3047fdd75cd6739b3"
Expand All @@ -3389,6 +3399,17 @@
"@sentry/utils" "6.17.7"
tslib "^1.9.3"

"@sentry/core@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.17.8.tgz#7dbdf394b47ed46048cbad6a8519cb3c4b84d6c4"
integrity sha512-4WTjgQom75Rvgn6XYy6e7vMIbWlj8utau1wWvr7kjqFKuuuuycRvPgVzAdVr4B3WDHHCInAZpUchsOLs2qwIEA==
dependencies:
"@sentry/hub" "6.17.8"
"@sentry/minimal" "6.17.8"
"@sentry/types" "6.17.8"
"@sentry/utils" "6.17.8"
tslib "^1.9.3"

"@sentry/hub@6.17.7":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.17.7.tgz#5c90d661e263dad7da0e0106f1cb90cf797d93a7"
Expand All @@ -3398,6 +3419,15 @@
"@sentry/utils" "6.17.7"
tslib "^1.9.3"

"@sentry/hub@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.17.8.tgz#d8b04647d12f80807f721c0e4e8133d3f78e4566"
integrity sha512-GW0XYpkoQu/kSJaTLfsF4extHDOBPNRnT0qKr/YO20Z5wGxYp8LsdnAuU3njcFHcAV2F/QDTj2BPq1U385/4+A==
dependencies:
"@sentry/types" "6.17.8"
"@sentry/utils" "6.17.8"
tslib "^1.9.3"

"@sentry/integrations@6.17.7":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-6.17.7.tgz#c14f409fec91743db4a21232413de235946cb6d3"
Expand All @@ -3408,6 +3438,16 @@
localforage "^1.8.1"
tslib "^1.9.3"

"@sentry/integrations@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-6.17.8.tgz#d53a257dd1fb375777e07b1682da9785059998fc"
integrity sha512-fULzgRG67SUsFnWZjYcN9urjFJlHSU1jfh9AshTDOEuzeMH4Vca0b3vMmXilylUA9g1+xKwF1KJgddH9toYjsQ==
dependencies:
"@sentry/types" "6.17.8"
"@sentry/utils" "6.17.8"
localforage "^1.8.1"
tslib "^1.9.3"

"@sentry/minimal@6.17.7":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.17.7.tgz#f19182047f19b563f40a30d45d2ce9ad7df1ec4e"
Expand All @@ -3417,6 +3457,15 @@
"@sentry/types" "6.17.7"
tslib "^1.9.3"

"@sentry/minimal@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.17.8.tgz#237ed91d8da00ecedc97ce7c1c3bd87a9b1ff1b7"
integrity sha512-VJXFZBO/O8SViK0fdzodxpNr+pbpgczNgLpz/MNuSooV6EBesgCMVjXtxDUp1Ie1odc0GUprN/ZMLYBmYdIrKQ==
dependencies:
"@sentry/hub" "6.17.8"
"@sentry/types" "6.17.8"
tslib "^1.9.3"

"@sentry/nextjs@^6.17.7":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/nextjs/-/nextjs-6.17.7.tgz#00e0380ba2b709674e495b3c00b24ee82405575d"
Expand All @@ -3432,6 +3481,21 @@
"@sentry/webpack-plugin" "1.18.5"
tslib "^1.9.3"

"@sentry/nextjs@^6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/nextjs/-/nextjs-6.17.8.tgz#234e89a33fe0d2b1cf99811cd67fccdd7b4cb782"
integrity sha512-6Kz5dHPXYAMDbTg2UiPXRPdcJbLL4bH68z1YIeyQpGotwwTH6VhjnRiIIDu4xHBWC6j9T6Bxg5CZHcALaTXteA==
dependencies:
"@sentry/core" "6.17.8"
"@sentry/hub" "6.17.8"
"@sentry/integrations" "6.17.8"
"@sentry/node" "6.17.8"
"@sentry/react" "6.17.8"
"@sentry/tracing" "6.17.8"
"@sentry/utils" "6.17.8"
"@sentry/webpack-plugin" "1.18.5"
tslib "^1.9.3"

"@sentry/node@6.17.7":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.17.7.tgz#c142d93328b29312098276e0cb66ec3b9e805a93"
Expand All @@ -3447,6 +3511,21 @@
lru_map "^0.3.3"
tslib "^1.9.3"

"@sentry/node@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.17.8.tgz#6debd3cdb60e51b227b90b2fae10a4ee745a6433"
integrity sha512-b3zg1XjKtxp7o821ENORO1CCzMM4QzKP01rzztMwyMcj28dmUq36QXoQAnwdKn7jEYkJdLnMeniIBR6U6NUJrQ==
dependencies:
"@sentry/core" "6.17.8"
"@sentry/hub" "6.17.8"
"@sentry/tracing" "6.17.8"
"@sentry/types" "6.17.8"
"@sentry/utils" "6.17.8"
cookie "^0.4.1"
https-proxy-agent "^5.0.0"
lru_map "^0.3.3"
tslib "^1.9.3"

"@sentry/react@6.17.7":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-6.17.7.tgz#550735bd9b56f20f15059f10a4573c80d5c882a5"
Expand All @@ -3459,6 +3538,18 @@
hoist-non-react-statics "^3.3.2"
tslib "^1.9.3"

"@sentry/react@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-6.17.8.tgz#d344fe9b9b450fa82c8313daac4936c9a0a6d9c2"
integrity sha512-9Be+Bf5bbjcf2isJXY0RM7ubPZUt4ZuX3lFjjFeCGhxrOp5EM9q+1c+OwIQo2Ml0mg9VmpFcSQPHd/qfUxwRbA==
dependencies:
"@sentry/browser" "6.17.8"
"@sentry/minimal" "6.17.8"
"@sentry/types" "6.17.8"
"@sentry/utils" "6.17.8"
hoist-non-react-statics "^3.3.2"
tslib "^1.9.3"

"@sentry/tracing@6.17.7":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.17.7.tgz#f4536683b29bb3ac7ddda5ca49494731cec6b619"
Expand All @@ -3470,11 +3561,27 @@
"@sentry/utils" "6.17.7"
tslib "^1.9.3"

"@sentry/tracing@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.17.8.tgz#a7a45aac3a1808afe946c1404538a8a1ab85a11b"
integrity sha512-WJ3W8O6iPI3w7MrzTnYcw3s5PGBNFqT4b9oBCl5Ndjexs8DsGlQOxjrsipo36z6TpnRHpAE4FEbOETb2R8JRJQ==
dependencies:
"@sentry/hub" "6.17.8"
"@sentry/minimal" "6.17.8"
"@sentry/types" "6.17.8"
"@sentry/utils" "6.17.8"
tslib "^1.9.3"

"@sentry/types@6.17.7", "@sentry/types@^6.11.0":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.17.7.tgz#61946a3f6532b8f21251b264f173b02f9ea2458e"
integrity sha512-iBlJDhrSowZKeqvutY0tCkUjrWqkLFsHrbaQ553r1Nx+/4mxHjzVYtEVGMjZAxQUEbkm0TbnQIkkT7ltglNJ9A==

"@sentry/types@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.17.8.tgz#f1f9fbf2f87f0374b6e122ae065da5ca679bc5ea"
integrity sha512-0i0f+dpvV62Pm5QMVBHNfEsTGIXoXRGQbeN2LGL4XbhzrzUmIrBPzrnZHv9c/JYtSJnI6A0B9OG7Bdlh3aku+Q==

"@sentry/utils@6.17.7":
version "6.17.7"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.17.7.tgz#0574bf914cc129b5e47041b75bb34dfbe0decbba"
Expand All @@ -3483,6 +3590,14 @@
"@sentry/types" "6.17.7"
tslib "^1.9.3"

"@sentry/utils@6.17.8":
version "6.17.8"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.17.8.tgz#a223f5184cbba8c4ad5ebd57800b6f368b274e48"
integrity sha512-cAOM53A5FHv95hpDuXKJU8rI4B1XdZ6qe3Yo+/nDS9QDpOgzvyjcItgXPvKW1wUjdHCcnwu7VBfBxB7teYOW9g==
dependencies:
"@sentry/types" "6.17.8"
tslib "^1.9.3"

"@sentry/webpack-plugin@1.18.5":
version "1.18.5"
resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-1.18.5.tgz#aaff79d8e05b8d803654490324252406c976b1cd"
Expand Down

4 comments on commit b339add

@vercel
Copy link

@vercel vercel bot commented on b339add Feb 15, 2022

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

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

@vercel
Copy link

@vercel vercel bot commented on b339add Feb 15, 2022

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-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on b339add Feb 15, 2022

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:

landing-page-v2 – ./apps/landing-page

landing-page-v2-typebot-io.vercel.app
www.get-typebot.com
get-typebot.com
landing-page-v2-git-main-typebot-io.vercel.app
typebot.io
www.typebot.io

@vercel
Copy link

@vercel vercel bot commented on b339add Feb 15, 2022

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-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

Please sign in to comment.