Log errors using Sentry (#655)

* feat: log errors using Sentry

* chore: set VERCEL_ENV

* wip: try to remove env and fix the build

* dont use sentry when building on local machine

* turn off sentry if no auth token in vercel build

* fix auth token check

* fix

* fix: specify vercel env

Co-authored-by: Sebastian Bor <Sebastian_Bor@hotmail.com>
Co-authored-by: Adrian Brzeziński <a.brzezinski94@gmail.com>
This commit is contained in:
Steven Luscher 2022-05-05 15:44:44 -07:00 committed by GitHub
parent 1259659500
commit a9494391ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 316 additions and 27 deletions

3
.gitignore vendored
View File

@ -35,3 +35,6 @@ yarn-error.log*
# TypeScript cache
*.tsbuildinfo
# Sentry
.sentryclirc

View File

@ -1,4 +1,4 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": ["Addin", "blockworks", "lamports", "solana"]
"cSpell.words": ["Addin", "blockworks", "lamports", "solana", "VERCEL"]
}

View File

@ -1,5 +1,6 @@
// workaround for ESM module loader errors
// see https://github.com/vercel/next.js/issues/25454
const { withSentryConfig } = require('@sentry/nextjs')
const withTM = require('next-transpile-modules')([
'react-markdown',
'@solana/wallet-adapter-base',
@ -10,23 +11,42 @@ const withTM = require('next-transpile-modules')([
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
let config
module.exports = withBundleAnalyzer(
withTM({
webpack: (config, { isServer }) => {
config.experiments = { asyncWebAssembly: true, layers: true }
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
})
if (!isServer) config.resolve.fallback.fs = false
return config
},
env: {
REALM: process.env.REALM,
MAINNET_RPC: process.env.MAINNET_RPC,
DEVNET_RPC: process.env.DEVNET_RPC,
DEFAULT_GOVERNANCE_PROGRAM_ID: process.env.DEFAULT_GOVERNANCE_PROGRAM_ID,
},
// STEP 1: Add transpiler.
config = withTM({
webpack: (config, { isServer }) => {
config.experiments = { asyncWebAssembly: true, layers: true }
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
})
if (!isServer) config.resolve.fallback.fs = false
return config
},
env: {
REALM: process.env.REALM,
MAINNET_RPC: process.env.MAINNET_RPC,
DEVNET_RPC: process.env.DEVNET_RPC,
DEFAULT_GOVERNANCE_PROGRAM_ID: process.env.DEFAULT_GOVERNANCE_PROGRAM_ID,
},
})
// STEP 2: Enable bundle analyzer when `ANALYZE=true`.
config = withBundleAnalyzer(config)
if (process.env.SENTRY_AUTH_TOKEN) {
// STEP 3: Sentry error reporting. MUST COME LAST to work with sourcemaps.
config = withSentryConfig(config, {
// 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.
})
)
}
module.exports = config

View File

@ -34,6 +34,7 @@
"@heroicons/react": "^1.0.1",
"@marinade.finance/marinade-ts-sdk": "^2.0.9",
"@metaplex-foundation/mpl-token-metadata": "^1.2.5",
"@mithraic-labs/serum-remote": "^0.0.1-rc.16",
"@next/bundle-analyzer": "^12.1.5",
"@mithraic-labs/serum-remote": "^0.0.1-rc.16",
"@nfteyez/sol-rayz": "^0.10.2",
@ -42,8 +43,9 @@
"@notifi-network/notifi-react-hooks": "^0.12.1",
"@project-serum/anchor": "^0.24.2",
"@project-serum/common": "^0.0.1-beta.3",
"@project-serum/sol-wallet-adapter": "^0.2.6",
"@project-serum/serum": "^0.13.61",
"@project-serum/sol-wallet-adapter": "^0.2.6",
"@sentry/nextjs": "^6.19.7",
"@solana/governance-program-library": "^0.15.2",
"@solana/spl-governance": "^0.0.34",
"@solana/spl-token": "0.1.8",

65
pages/_error.js Normal file
View File

@ -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

View File

@ -14,6 +14,7 @@ import { getAllSplGovernanceProgramIds } from './tools/realms'
import BigNumber from 'bignumber.js'
import BN from 'bn.js'
import { WSOL_MINT_PK } from '@components/instructions/tools'
import { withSentry } from '@sentry/nextjs'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const conn = new Connection(
@ -143,4 +144,4 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json(daoStatistics)
}
export default handler
export default withSentry(handler)

View File

@ -1,3 +1,4 @@
import { withSentry } from '@sentry/nextjs'
import {
getGovernanceAccounts,
ProgramAccount,
@ -79,4 +80,4 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json(daoStatistics)
}
export default handler
export default withSentry(handler)

View File

@ -1,9 +1,10 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { withSentry } from '@sentry/nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json({ name: 'John Doe' })
}
export default handler
export default withSentry(handler)

View File

@ -1,3 +1,4 @@
import { withSentry } from '@sentry/nextjs'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAllSplGovernanceProgramIds } from './tools/realms'
@ -6,4 +7,4 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json(getAllSplGovernanceProgramIds())
}
export default handler
export default withSentry(handler)

21
sentry.client.config.js Normal file
View File

@ -0,0 +1,21 @@
// 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'
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
const SENTRY_ENVIRONMENT = process.env.VERCEL_ENV
Sentry.init({
dsn:
SENTRY_DSN ||
'https://18ab56d9b27a4483a29e51d6520afbc6@o434108.ingest.sentry.io/6380292',
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
environment: SENTRY_ENVIRONMENT,
// ...
// 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
sentry.properties Normal file
View File

@ -0,0 +1,4 @@
defaults.url=https://sentry.io/
defaults.org=solana
defaults.project=realms
cli.executable=../../../.npm/_npx/a8388072043b4cbc/node_modules/@sentry/cli/bin/sentry-cli

21
sentry.server.config.js Normal file
View File

@ -0,0 +1,21 @@
// 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'
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
const SENTRY_ENVIRONMENT = process.env.VERCEL_ENV
Sentry.init({
dsn:
SENTRY_DSN ||
'https://18ab56d9b27a4483a29e51d6520afbc6@o434108.ingest.sentry.io/6380292',
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
environment: SENTRY_ENVIRONMENT,
// ...
// 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
})

155
yarn.lock
View File

@ -2123,6 +2123,140 @@
tslib "^2.3.1"
unstated-next "^1.1.0"
"@sentry/browser@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/browser/-/browser-6.19.7.tgz#a40b6b72d911b5f1ed70ed3b4e7d4d4e625c0b5f"
integrity sha512-oDbklp4O3MtAM4mtuwyZLrgO1qDVYIujzNJQzXmi9YzymJCuzMLSRDvhY83NNDCRxf0pds4DShgYeZdbSyKraA==
dependencies:
"@sentry/core" "6.19.7"
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
tslib "^1.9.3"
"@sentry/cli@^1.73.0":
version "1.74.4"
resolved "https://registry.npmjs.org/@sentry/cli/-/cli-1.74.4.tgz#7df82f68045a155e1885bfcbb5d303e5259eb18e"
integrity sha512-BMfzYiedbModsNBJlKeBOLVYUtwSi99LJ8gxxE4Bp5N8hyjNIN0WVrozAVZ27mqzAuy6151Za3dpmOLO86YlGw==
dependencies:
https-proxy-agent "^5.0.0"
mkdirp "^0.5.5"
node-fetch "^2.6.7"
npmlog "^4.1.2"
progress "^2.0.3"
proxy-from-env "^1.1.0"
which "^2.0.2"
"@sentry/core@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/core/-/core-6.19.7.tgz#156aaa56dd7fad8c89c145be6ad7a4f7209f9785"
integrity sha512-tOfZ/umqB2AcHPGbIrsFLcvApdTm9ggpi/kQZFkej7kMphjT+SGBiQfYtjyg9jcRW+ilAR4JXC9BGKsdEQ+8Vw==
dependencies:
"@sentry/hub" "6.19.7"
"@sentry/minimal" "6.19.7"
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
tslib "^1.9.3"
"@sentry/hub@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/hub/-/hub-6.19.7.tgz#58ad7776bbd31e9596a8ec46365b45cd8b9cfd11"
integrity sha512-y3OtbYFAqKHCWezF0EGGr5lcyI2KbaXW2Ik7Xp8Mu9TxbSTuwTe4rTntwg8ngPjUQU3SUHzgjqVB8qjiGqFXCA==
dependencies:
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
tslib "^1.9.3"
"@sentry/integrations@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/integrations/-/integrations-6.19.7.tgz#e6e126b692077c8731644224c754012bed65b425"
integrity sha512-yNeeFyuygJaV7Mdc5qWuDa13xVj5mVdECaaw2Xs4pfeHaXmRfRzZY17N8ypWFegKWxKBHynyQRMD10W5pBwJvA==
dependencies:
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
localforage "^1.8.1"
tslib "^1.9.3"
"@sentry/minimal@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/minimal/-/minimal-6.19.7.tgz#b3ee46d6abef9ef3dd4837ebcb6bdfd01b9aa7b4"
integrity sha512-wcYmSJOdvk6VAPx8IcmZgN08XTXRwRtB1aOLZm+MVHjIZIhHoBGZJYTVQS/BWjldsamj2cX3YGbGXNunaCfYJQ==
dependencies:
"@sentry/hub" "6.19.7"
"@sentry/types" "6.19.7"
tslib "^1.9.3"
"@sentry/nextjs@^6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/nextjs/-/nextjs-6.19.7.tgz#2c40692d89a99ec1382189f11702b1498c91fb77"
integrity sha512-029gpqhR6gHF7zfE9oxFOf3Zm68CShDu8/6azC8mwfIfJtyLC9dqztJJi48j0Uxs+sR1TEkN5Dw3wZbfWtFd8g==
dependencies:
"@sentry/core" "6.19.7"
"@sentry/hub" "6.19.7"
"@sentry/integrations" "6.19.7"
"@sentry/node" "6.19.7"
"@sentry/react" "6.19.7"
"@sentry/tracing" "6.19.7"
"@sentry/utils" "6.19.7"
"@sentry/webpack-plugin" "1.18.8"
tslib "^1.9.3"
"@sentry/node@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/node/-/node-6.19.7.tgz#32963b36b48daebbd559e6f13b1deb2415448592"
integrity sha512-gtmRC4dAXKODMpHXKfrkfvyBL3cI8y64vEi3fDD046uqYcrWdgoQsffuBbxMAizc6Ez1ia+f0Flue6p15Qaltg==
dependencies:
"@sentry/core" "6.19.7"
"@sentry/hub" "6.19.7"
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
cookie "^0.4.1"
https-proxy-agent "^5.0.0"
lru_map "^0.3.3"
tslib "^1.9.3"
"@sentry/react@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/react/-/react-6.19.7.tgz#58cc2d6da20f7d3b0df40638dfbbbc86c9c85caf"
integrity sha512-VzJeBg/v41jfxUYPkH2WYrKjWc4YiMLzDX0f4Zf6WkJ4v3IlDDSkX6DfmWekjTKBho6wiMkSNy2hJ1dHfGZ9jA==
dependencies:
"@sentry/browser" "6.19.7"
"@sentry/minimal" "6.19.7"
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
hoist-non-react-statics "^3.3.2"
tslib "^1.9.3"
"@sentry/tracing@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/tracing/-/tracing-6.19.7.tgz#54bb99ed5705931cd33caf71da347af769f02a4c"
integrity sha512-ol4TupNnv9Zd+bZei7B6Ygnr9N3Gp1PUrNI761QSlHtPC25xXC5ssSD3GMhBgyQrcvpuRcCFHVNNM97tN5cZiA==
dependencies:
"@sentry/hub" "6.19.7"
"@sentry/minimal" "6.19.7"
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
tslib "^1.9.3"
"@sentry/types@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/types/-/types-6.19.7.tgz#c6b337912e588083fc2896eb012526cf7cfec7c7"
integrity sha512-jH84pDYE+hHIbVnab3Hr+ZXr1v8QABfhx39KknxqKWr2l0oEItzepV0URvbEhB446lk/S/59230dlUUIBGsXbg==
"@sentry/utils@6.19.7":
version "6.19.7"
resolved "https://registry.npmjs.org/@sentry/utils/-/utils-6.19.7.tgz#6edd739f8185fd71afe49cbe351c1bbf5e7b7c79"
integrity sha512-z95ECmE3i9pbWoXQrD/7PgkBAzJYR+iXtPuTkpBjDKs86O3mT+PXOT3BAn79w2wkn7/i3vOGD2xVr1uiMl26dA==
dependencies:
"@sentry/types" "6.19.7"
tslib "^1.9.3"
"@sentry/webpack-plugin@1.18.8":
version "1.18.8"
resolved "https://registry.npmjs.org/@sentry/webpack-plugin/-/webpack-plugin-1.18.8.tgz#247a73a0aa9e28099a736bbe89ca0d35cbac7636"
integrity sha512-PtKr0NL62b5L3kPFGjwSNbIUwwcW5E5G6bQxAYZGpkgL1MFPnS4ND0SAsySuX0byQJRFFium5A19LpzyvQZSlQ==
dependencies:
"@sentry/cli" "^1.73.0"
"@sinonjs/commons@^1.7.0":
version "1.8.3"
resolved "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz"
@ -4300,6 +4434,11 @@ cookie@0.4.1:
resolved "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz"
integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==
cookie@^0.4.1:
version "0.4.2"
resolved "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432"
integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==
copy-descriptor@^0.1.0:
version "0.1.1"
resolved "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz"
@ -6137,7 +6276,7 @@ hmac-drbg@^1.0.1:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.1"
hoist-non-react-statics@^3.3.1:
hoist-non-react-statics@^3.3.1, hoist-non-react-statics@^3.3.2:
version "3.3.2"
resolved "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz"
dependencies:
@ -7785,7 +7924,7 @@ listr2@^3.2.2:
through "^2.3.8"
wrap-ansi "^7.0.0"
localforage@^1.10.0:
localforage@^1.10.0, localforage@^1.8.1:
version "1.10.0"
resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.10.0.tgz#5c465dc5f62b2807c3a84c0c6a1b1b3212781dd4"
integrity sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==
@ -7945,6 +8084,11 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"
lru_map@^0.3.3:
version "0.3.3"
resolved "https://registry.npmjs.org/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=
lunr@^2.3.9:
version "2.3.9"
resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.9.tgz#18b123142832337dd6e964df1a5a7707b25d35e1"
@ -8876,7 +9020,7 @@ node-fetch@2.6.1, node-fetch@^2.6.1:
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
node-fetch@2.6.7:
node-fetch@2.6.7, node-fetch@^2.6.7:
version "2.6.7"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
@ -10088,6 +10232,11 @@ proxy-addr@~2.0.7:
forwarded "0.2.0"
ipaddr.js "1.9.1"
proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
prr@~1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz"