Task/33 add sentry to trading (#189)

* add sentry setup, add VEGA_ENV to env files

* rename custom error page

* capture exception for eager connect

* add link to setup docs in comment

* add browser tracing plugin

* define sentry auth token once

* enable sourcemaps on build

* use correct sentry config property
This commit is contained in:
Matthew Russell 2022-04-04 12:45:40 -07:00 committed by GitHub
parent a459793f09
commit 018e5fe139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 279 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import { Given, Then, When } from 'cypress-cucumber-preprocessor/steps';
import { Given, When } from 'cypress-cucumber-preprocessor/steps';
import MarketsPage from '../pages/markets-page';
import DealTicketPage from '../pages/deal-ticket-page';
const marketsPage = new MarketsPage();

View File

@ -1,4 +1,4 @@
import { Given, Then, When } from 'cypress-cucumber-preprocessor/steps';
import { Then, When } from 'cypress-cucumber-preprocessor/steps';
import MarketsPage from '../pages/markets-page';
const marketsPage = new MarketsPage();

View File

@ -1,4 +1,4 @@
import { Given, Then, When } from 'cypress-cucumber-preprocessor/steps';
import { Then, When } from 'cypress-cucumber-preprocessor/steps';
import MarketsPage from '../pages/markets-page';
import DealTicketPage from '../pages/deal-ticket-page';
const marketsPage = new MarketsPage();

View File

@ -1,4 +1,5 @@
# App configuration variables
NX_VEGA_ENV = "DEVNET"
NX_VEGA_URL = "https://n04.d.vega.xyz/query"
NX_ETHEREUM_CHAIN_ID = 3
NX_INFURA_ID = "4f846e79e13f44d1b51bbd7ed9edefb8"

View File

@ -1,4 +1,5 @@
# App configuration variables
NX_VEGA_ENV = "MAINNET"
NX_VEGA_URL = "https://api.token.vega.xyz/query"
NX_ETHEREUM_CHAIN_ID = 1
NX_INFURA_ID = "4f846e79e13f44d1b51bbd7ed9edefb8"

View File

@ -1,4 +1,5 @@
# App configuration variables
NX_VEGA_ENV = "STAGNET"
NX_VEGA_URL = "https://n03.s.vega.xyz/query"
NX_ETHEREUM_CHAIN_ID = 3
NX_INFURA_ID = "4f846e79e13f44d1b51bbd7ed9edefb8"

View File

@ -1,4 +1,5 @@
# App configuration variables
NX_VEGA_ENV = "STAGNET2"
NX_VEGA_URL = "https://n03.stagnet2.vega.xyz/query"
NX_ETHEREUM_CHAIN_ID = 3
NX_INFURA_ID = "4f846e79e13f44d1b51bbd7ed9edefb8"

View File

@ -1,4 +1,5 @@
# App configuration variables
NX_VEGA_ENV = "TESTNET"
NX_VEGA_URL = "https://lb.testnet.vega.xyz/query"
NX_ETHEREUM_CHAIN_ID = 3
NX_INFURA_ID = "4f846e79e13f44d1b51bbd7ed9edefb8"

View File

@ -2,6 +2,7 @@ import { useVegaWallet, WALLET_CONFIG } from '@vegaprotocol/wallet';
import { useEffect } from 'react';
import { LocalStorage } from '@vegaprotocol/react-helpers';
import { Connectors } from '../lib/vega-connectors';
import { captureException } from '@sentry/nextjs';
export function useEagerConnect() {
const { connect } = useVegaWallet();
@ -27,8 +28,10 @@ export function useEagerConnect() {
// Developer hasn't provided this connector
if (!connector) {
console.warn(
`Can't eager connect, connector: ${cfgObj.connector} not found`
captureException(
new Error(
`Can't eager connect, connector: ${cfgObj.connector} not found`
)
);
return;
}

View File

@ -1,5 +1,14 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const withNx = require('@nrwl/next/plugins/with-nx');
const { withSentryConfig } = require('@sentry/nextjs');
const SENTRY_AUTH_TOKEN = process.env.SENTRY_AUTH_TOKEN;
const sentryWebpackOptions = {
org: 'vega-o3',
project: 'trading',
token: SENTRY_AUTH_TOKEN,
};
/**
* @type {import('@nrwl/next/plugins/with-nx').WithNxOptions}
@ -17,4 +26,6 @@ const nextConfig = {
},
};
module.exports = withNx(nextConfig);
module.exports = SENTRY_AUTH_TOKEN
? withNx(withSentryConfig(nextConfig, sentryWebpackOptions))
: withNx(nextConfig);

View File

@ -0,0 +1,81 @@
import NextErrorComponent from 'next/error';
import type { NextPageContext } from 'next';
import { captureException, flush } from '@sentry/nextjs';
interface ErrorPageProps {
statusCode: number;
hasGetInitialPropsRun: boolean;
err: Error;
}
/**
* This error component is taken from the Sentry's next js setup docs.
* https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
*/
const ErrorPage = ({
statusCode,
hasGetInitialPropsRun,
err,
}: ErrorPageProps) => {
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
captureException(err);
// Flushing is not required in this case as it only happens on the client
}
return <NextErrorComponent statusCode={statusCode} />;
};
ErrorPage.getInitialProps = async ({
res,
err,
asPath,
...props
}: NextPageContext) => {
const errorInitialProps = await NextErrorComponent.getInitialProps({
res,
err,
...props,
});
// @ts-ignore Workaround for https://github.com/vercel/next.js/issues/8592, mark when
// getInitialProps has run
errorInitialProps.hasGetInitialPropsRun = true;
// 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) {
captureException(err);
// Flushing before returning is necessary if deploying to Vercel, see
// https://vercel.com/docs/platform/limits#streaming-responses
await 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
captureException(
new Error(`_error.js getInitialProps missing data at path: ${asPath}`)
);
await flush(2000);
return errorInitialProps;
};
export default ErrorPage;

View File

@ -12,7 +12,10 @@
"outputPath": "dist/apps/trading"
},
"configurations": {
"production": {}
"production": {
"optimization": true,
"sourceMap": true
}
}
},
"serve": {

View File

@ -0,0 +1,13 @@
import * as Sentry from '@sentry/nextjs';
import { BrowserTracing } from '@sentry/tracing';
const dsn = process.env['NX_TRADING_SENTRY_DSN'];
if (dsn) {
Sentry.init({
dsn,
integrations: [new BrowserTracing()],
tracesSampleRate: 1,
environment: process.env['NX_VEGA_ENV'],
});
}

View File

@ -0,0 +1,13 @@
import * as Sentry from '@sentry/nextjs';
import { BrowserTracing } from '@sentry/tracing';
const dsn = process.env['NX_TRADING_SENTRY_DSN'];
if (dsn) {
Sentry.init({
dsn,
integrations: [new BrowserTracing()],
tracesSampleRate: 1,
environment: process.env['NX_VEGA_ENV'],
});
}

View File

@ -1,6 +1,5 @@
import { useApplyGridTransaction } from './use-apply-grid-transaction';
import { renderHook } from '@testing-library/react-hooks';
import { GridApi } from 'ag-grid-community';
type Items = Array<{ id: string; value: number }>;
@ -25,6 +24,7 @@ function setup(items: Items, rowNodes: Items) {
return undefined;
},
};
// eslint-disable-next-line
renderHook(() => useApplyGridTransaction(items, gridApiMock as any));
return gridApiMock;
}

View File

@ -10,6 +10,7 @@ describe('findFirstDiffPos', () => {
it('Returns -1 if a string is undefined (just in case)', () => {
const a = 'test';
// eslint-disable-next-line
const b = undefined as any as string;
expect(findFirstDiffPos(a, b)).toEqual(-1);

View File

@ -19,6 +19,7 @@
"@radix-ui/react-dialog": "^0.1.5",
"@radix-ui/react-tabs": "^0.1.5",
"@radix-ui/react-tooltip": "^0.1.7",
"@sentry/nextjs": "^6.19.3",
"@sentry/react": "^6.19.2",
"@sentry/tracing": "^6.19.2",
"@types/lodash": "^4.14.180",

142
yarn.lock
View File

@ -3626,6 +3626,16 @@
"@sentry/utils" "6.19.2"
tslib "^1.9.3"
"@sentry/browser@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.19.3.tgz#b4cfc6eba48d10a5fdf096c05ca11303354edb8b"
integrity sha512-E8UA6IN8z9hL6aGzOHUzqgNZiBwARkA89i8ncKB9QU1/+jl7598ZLziN4+uyPeZiRquEz8Ub7Ve1eacs1u+fbw==
dependencies:
"@sentry/core" "6.19.3"
"@sentry/types" "6.19.3"
"@sentry/utils" "6.19.3"
tslib "^1.9.3"
"@sentry/cli@^1.73.0":
version "1.74.2"
resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-1.74.2.tgz#3821ec2fe1a027c6bb6c802ea3ae4f63a21e2533"
@ -3650,6 +3660,17 @@
"@sentry/utils" "6.19.2"
tslib "^1.9.3"
"@sentry/core@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.19.3.tgz#88268afc8c42716c455ad77bb4bed2bbf96abd83"
integrity sha512-RcGmYdkrE3VYBMl9Hgv4GKsC8FEVUdWYsfGIcT/btwP2YpBeUaTZl+1vV9r3Ncdl125LqzP5CKSj5otVxiEg6g==
dependencies:
"@sentry/hub" "6.19.3"
"@sentry/minimal" "6.19.3"
"@sentry/types" "6.19.3"
"@sentry/utils" "6.19.3"
tslib "^1.9.3"
"@sentry/hub@6.19.2":
version "6.19.2"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.19.2.tgz#0e9f9c507e55d8396002f644b43ef27cc9ff1289"
@ -3659,6 +3680,25 @@
"@sentry/utils" "6.19.2"
tslib "^1.9.3"
"@sentry/hub@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.19.3.tgz#d555c83404f19ac9b68f336b051b8e7a9d75feb0"
integrity sha512-iYbkrxEZt6CrHP3U3r54MARVZSs3YHjAMUMOTlC16s/Amz1McwV95XtI3NJaqMhwzl7R5vbGrs3xOtLg1V1Uyw==
dependencies:
"@sentry/types" "6.19.3"
"@sentry/utils" "6.19.3"
tslib "^1.9.3"
"@sentry/integrations@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-6.19.3.tgz#b5ac64591a9c7ae60f54c7d5ebd0d9152215c377"
integrity sha512-hOyX0UoH1ZyFtOjIazL2M9HfQMIjwukv0AtTX2W7sVfV1qxvISaV5lYZrAw1xB1lRoUwOJr/C0odddHWtBgdsA==
dependencies:
"@sentry/types" "6.19.3"
"@sentry/utils" "6.19.3"
localforage "^1.8.1"
tslib "^1.9.3"
"@sentry/minimal@6.19.2":
version "6.19.2"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.19.2.tgz#e748541e4adbc7e80a3b6ccaf01b631c17fc44b4"
@ -3668,6 +3708,56 @@
"@sentry/types" "6.19.2"
tslib "^1.9.3"
"@sentry/minimal@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.19.3.tgz#b9b7f0d7f0cd2341b243318668ac01458f9d7889"
integrity sha512-xy/6ThHK8B2NJT98nWrx6V9eVgUbzq2N/8lv5/QqrKsICjxx22TRC8Q6zPg/o7BYcrY5vpugSEbIeErTnyxHDA==
dependencies:
"@sentry/hub" "6.19.3"
"@sentry/types" "6.19.3"
tslib "^1.9.3"
"@sentry/nextjs@^6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/nextjs/-/nextjs-6.19.3.tgz#3e56ebfd0409a263c360bb275d2cfe3deffbf259"
integrity sha512-+Gw69DDW89VIi0SMqBFNZpSMhKH9VBCSubhm94gFae3u4eoRs8ZChuNuhbnScmE7OsJ4uLOnnu4Y186yCY7RpQ==
dependencies:
"@sentry/core" "6.19.3"
"@sentry/hub" "6.19.3"
"@sentry/integrations" "6.19.3"
"@sentry/node" "6.19.3"
"@sentry/react" "6.19.3"
"@sentry/tracing" "6.19.3"
"@sentry/utils" "6.19.3"
"@sentry/webpack-plugin" "1.18.8"
tslib "^1.9.3"
"@sentry/node@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.19.3.tgz#afcf106bf72acc0e4bbacbc54744de8a938cbd1c"
integrity sha512-eHreMMbaK4mMAQ45Ki2xJ6in02l66hL6xhltppy/h4m297JIvjaQAFpbQf5XLtO7W4KjdbSV5qnB45D1aOAzFA==
dependencies:
"@sentry/core" "6.19.3"
"@sentry/hub" "6.19.3"
"@sentry/types" "6.19.3"
"@sentry/utils" "6.19.3"
cookie "^0.4.1"
https-proxy-agent "^5.0.0"
lru_map "^0.3.3"
tslib "^1.9.3"
"@sentry/react@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-6.19.3.tgz#6b2bfb19faa55cf83af593a5778bb23cd2cf60a3"
integrity sha512-Zza1RX0+1tFCM1Hfq3Yl50cbc/ml0V/katw4aVZIU6+vEgvk5EuSFKU2LtblmJkpID7x6UwWz+1qgXumZPze6Q==
dependencies:
"@sentry/browser" "6.19.3"
"@sentry/minimal" "6.19.3"
"@sentry/types" "6.19.3"
"@sentry/utils" "6.19.3"
hoist-non-react-statics "^3.3.2"
tslib "^1.9.3"
"@sentry/react@^6.19.2":
version "6.19.2"
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-6.19.2.tgz#67760aed06d7e54a2e117cd9048ad19d573c78f1"
@ -3680,6 +3770,17 @@
hoist-non-react-statics "^3.3.2"
tslib "^1.9.3"
"@sentry/tracing@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.19.3.tgz#dfdbd5019486c899bdf352b1152d5d253544ef70"
integrity sha512-3lyb4yCFH/ltEQSyKM96g2c74vvKIwByx8fLDS4FHYQQDXY+xPcs+zyK8L1Fs5PRFAUciEOK5TS9qwELom5K4w==
dependencies:
"@sentry/hub" "6.19.3"
"@sentry/minimal" "6.19.3"
"@sentry/types" "6.19.3"
"@sentry/utils" "6.19.3"
tslib "^1.9.3"
"@sentry/tracing@^6.19.2":
version "6.19.2"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.19.2.tgz#ed6ff1bc901c4d79ef97f77ed54ce58c650e4915"
@ -3696,6 +3797,11 @@
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.19.2.tgz#0219c9da21ed975951108b8541913b1966464435"
integrity sha512-XO5qmVBdTs+7PdCz7fAwn1afWxSnRE2KLBFg5/vOdKosPSSHsSHUURSkxiEZc2QsR+JpRB4AeQ26AkIRX38qTg==
"@sentry/types@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.19.3.tgz#94b19da68d4d23561efb1014f72968bcea85cd0c"
integrity sha512-jHhqxp8MIWSfOc3krorirTGKTEaSFO6XrAvi+2AZhr6gvOChwOgzgrN2ZqesJcZmgCsqWV21u3usSwYeRrjOJA==
"@sentry/utils@6.19.2":
version "6.19.2"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.19.2.tgz#995efb896c5159369509f4896c27a2d2ea9191f2"
@ -3704,7 +3810,15 @@
"@sentry/types" "6.19.2"
tslib "^1.9.3"
"@sentry/webpack-plugin@^1.18.8":
"@sentry/utils@6.19.3":
version "6.19.3"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.19.3.tgz#0c3a3f0b86c12e3b079e56e37a44e62a1226043d"
integrity sha512-GdC9B/FK7qd0zItY43135bYbhuVSawE18bIrQDNuno8gTpDJ5OgShpTN9zR53AmMh16/lwKNnV3ZZjlpKcxuNw==
dependencies:
"@sentry/types" "6.19.3"
tslib "^1.9.3"
"@sentry/webpack-plugin@1.18.8", "@sentry/webpack-plugin@^1.18.8":
version "1.18.8"
resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-1.18.8.tgz#247a73a0aa9e28099a736bbe89ca0d35cbac7636"
integrity sha512-PtKr0NL62b5L3kPFGjwSNbIUwwcW5E5G6bQxAYZGpkgL1MFPnS4ND0SAsySuX0byQJRFFium5A19LpzyvQZSlQ==
@ -8955,7 +9069,7 @@ cookie-signature@1.0.6:
resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c"
integrity sha1-4wOogrNCzD7oylE6eZmXNNqzriw=
cookie@0.4.2:
cookie@0.4.2, cookie@^0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432"
integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==
@ -12522,6 +12636,11 @@ image-size@~0.5.0:
resolved "https://registry.yarnpkg.com/image-size/-/image-size-0.5.5.tgz#09dfd4ab9d20e29eb1c3e80b8990378df9e3cb9c"
integrity sha1-Cd/Uq50g4p6xw+gLiZA3jfnjy5w=
immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
integrity sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=
immer@^9.0.12:
version "9.0.12"
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.12.tgz#2d33ddf3ee1d247deab9d707ca472c8c942a0f20"
@ -14156,6 +14275,13 @@ license-webpack-plugin@4.0.0:
dependencies:
webpack-sources "^3.0.0"
lie@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.1.1.tgz#9a436b2cc7746ca59de7a41fa469b3efb76bd87e"
integrity sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=
dependencies:
immediate "~3.0.5"
lilconfig@2.0.4, lilconfig@^2.0.3, lilconfig@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-2.0.4.tgz#f4507d043d7058b380b6a8f5cb7bcd4b34cee082"
@ -14319,6 +14445,13 @@ loader-utils@^3.2.0:
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-3.2.0.tgz#bcecc51a7898bee7473d4bc6b845b23af8304d4f"
integrity sha512-HVl9ZqccQihZ7JM85dco1MvO9G+ONvxoGa9rkhzFsneGLKSUg1gJf9bWzhRhcvm2qChhWpebQhP44qxjKIUCaQ==
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==
dependencies:
lie "3.1.1"
locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
@ -14526,6 +14659,11 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"
lru_map@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=
lz-string@^1.4.4:
version "1.4.4"
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26"