Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SENTRY] Add chainId tag and user to context #751

Merged
merged 10 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@
"@gnosis.pm/safe-service-client": "^0.1.1",
"@popperjs/core": "^2.4.4",
"@reduxjs/toolkit": "^1.8.0",
"@sentry/react": "^6.11.0",
"@sentry/tracing": "^6.11.0",
"@sentry/react": "^7.3.0",
"@sentry/tracing": "^7.3.0",
W3stside marked this conversation as resolved.
Show resolved Hide resolved
"@sentry/webpack-plugin": "^1.17.1",
"@uniswap/redux-multicall": "^1.1.1",
"@uniswap/router-sdk": "^1.0.3",
Expand All @@ -261,15 +261,15 @@
"@uniswap/token-lists": "^1.0.0-beta.27",
"@uniswap/v2-sdk": "^3.0.1",
"@uniswap/v3-sdk": "^3.8.2",
"@walletconnect/web3-provider": "^1.6.6",
"@web3-react/core": "^8.0.23-beta.0",
"@web3-react/eip1193": "^8.0.18-beta.0",
"@web3-react/empty": "^8.0.12-beta.0",
"@web3-react/types": "^8.0.12-beta.0",
"@web3-react/url": "^8.0.17-beta.0",
"@walletconnect/web3-provider": "^1.6.6",
"@web3-react/fortmatic-connector": "^6.1.6",
"@web3-react/injected-connector": "^6.0.7",
"@web3-react/portis-connector": "^6.1.9",
"@web3-react/types": "^8.0.12-beta.0",
"@web3-react/url": "^8.0.17-beta.0",
"@web3-react/walletconnect-connector": "^7.0.2-alpha.0",
"@web3-react/walletlink-connector": "^6.2.5",
"ajv": "^6.12.3",
Expand Down
2 changes: 1 addition & 1 deletion src/custom/api/gnosisProtocol/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function _handleError<P extends Context>(error: any, response: Response, params:
Sentry.captureException(sentryError, {
tags,
// TODO: change/remove this in context update pr
contexts: { params: { ...params } },
contexts: { params },
})

return error?.baseError || error
Expand Down
1 change: 1 addition & 0 deletions src/custom/api/gnosisProtocol/errors/QuoteError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export enum GpQuoteErrorDetails {
FeeExceedsFrom = 'Current fee exceeds entered "from" amount.',
ZeroPrice = 'Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.',
TransferEthToContract = 'Buying native currencies using smart contract wallets is not currently supported.',
SellAmountDoesNotCoverFee = 'The selling amount for the order is lower than the fee.',
UNHANDLED_ERROR = 'Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later.',
}

Expand Down
79 changes: 64 additions & 15 deletions src/custom/state/sentry/updater/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,93 @@ import * as Sentry from '@sentry/browser'

import useIsWindowVisible from 'hooks/useIsWindowVisible'
import { useSwapState } from 'state/swap/hooks'
import { SupportedChainId } from 'constants/chains'
import { useCurrency } from 'hooks/Tokens'
import { useWalletInfo } from 'hooks/useWalletInfo'
import { useAppSelector } from 'state/hooks'

enum SentryTag {
DISCONNECTED = 'DISCONNECTED',
UNKNOWN = 'UNKNOWN',
}

/**
* _getSentryChainId
* @param appChainId - redux chainId (not necessarily connected to a wallet)
* @param connectedChainId - wallet chainId
* @returns string e.g "DISCONNECTED" | appChainId | connectedChainId
*/
function _getSentryChainIdAndConnectionStatus(
appChainId: number | null,
connectedChainId: number | undefined
): [string, boolean] {
// match connectedChainId type
const appChainNormalised = appChainId ?? undefined

let sentryChainId
let connected
W3stside marked this conversation as resolved.
Show resolved Hide resolved
// neither connected
if (appChainNormalised === undefined && connectedChainId === undefined) {
connected = false
} else if (connectedChainId === undefined) {
// user is browsing app disconnected from wallet
sentryChainId = appChainNormalised
connected = false
} else {
// connectedChainId takes precedence
sentryChainId = connectedChainId
connected = true
}

// if not connected, sentry doesn't accept undefined, use "DISCONNECTED"
return [sentryChainId?.toString() || SentryTag.DISCONNECTED, connected]
}

export default function Updater(): null {
const { account, chainId, walletName, isSupportedWallet } = useWalletInfo()
const { account, chainId: connectedChainId, walletName } = useWalletInfo()
// app chain id maintains state for users disconnected but browsing app
const disconnectedChainId = useAppSelector((state) => state.application.chainId)
const windowVisible = useIsWindowVisible()

const {
INPUT: { currencyId: sellTokenAddress },
OUTPUT: { currencyId: buyTokenAddress },
} = useSwapState()

const sellCurrency = useCurrency(sellTokenAddress)
const buyCurrency = useCurrency(buyTokenAddress)
const { symbol: buySymbol, name: buyName } = useCurrency(buyTokenAddress) || {}
const { symbol: sellSymbol, name: sellName } = useCurrency(sellTokenAddress) || {}

// create sentry context based on "main" parameters
useEffect(() => {
if (windowVisible) {
Sentry.setContext('user', {
// userAddress: account || 'DISCONNECTED', // TODO: validate with legal
wallet: walletName,
network: chainId ? SupportedChainId[chainId] : chainId,
sellToken: `${sellTokenAddress} <${sellCurrency?.symbol}>`,
buyToken: `${buyTokenAddress} <${buyCurrency?.symbol}>`,
const [chainId, connected] = _getSentryChainIdAndConnectionStatus(disconnectedChainId, connectedChainId)
// setup scope/context/tags
Sentry.configureScope(function (scope) {
// setup a context
scope.setContext('user', {
user: account || SentryTag.DISCONNECTED,
sellToken: `${sellTokenAddress} <${sellSymbol || sellName}>`,
buyToken: `${buyTokenAddress} <${buySymbol || buyName}>`,
})
// also set tags for each session
scope.setTag('chainId', chainId)
W3stside marked this conversation as resolved.
Show resolved Hide resolved
// connectivity tag
scope.setTag('walletConnected', connected)
// set walletName tag
scope.setTag('wallet', walletName || SentryTag.UNKNOWN)
})
}
}, [
// user
account,
chainId,
connectedChainId,
disconnectedChainId,
walletName,
isSupportedWallet,
// tokens
sellSymbol,
sellName,
buySymbol,
buyName,
sellTokenAddress,
buyTokenAddress,
buyCurrency?.symbol,
sellCurrency?.symbol,
// window visibility check
windowVisible,
])
Expand Down
8 changes: 5 additions & 3 deletions src/custom/utils/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@ export async function getFullQuote({ quoteParams }: { quoteParams: LegacyFeeQuot
function _checkFeeErrorForData(error: GpQuoteError) {
console.warn('[getBestQuote:Legacy]::Fee error', error)

const feeAmount = error?.data?.fee_amount || error?.data?.feeAmount
const feeExpiration = error?.data?.expiration
// check if our error response has any fee data attached to it
if (error?.data) {
if (feeAmount) {
return {
amount: error?.data.feeAmount,
expirationDate: error?.data.expiration,
amount: feeAmount,
expirationDate: feeExpiration,
}
} else {
// no data object, just rethrow
Expand Down
118 changes: 46 additions & 72 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3601,14 +3601,14 @@
dependencies:
any-observable "^0.3.0"

"@sentry/browser@6.19.7":
version "6.19.7"
resolved "https://registry.yarnpkg.com/@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"
"@sentry/browser@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.3.0.tgz#b62cdfeb60ab65cc1a98f84d8e4a519842e79a3e"
integrity sha512-UJMTDbajKNRGrs4ZQNelrPDaATvSZ9uELpPOtPSG6JUvB1BCwGgsgzz55RS0Uqs7B8KhMnDQ0kIn3FMewM4FMg==
dependencies:
"@sentry/core" "7.3.0"
"@sentry/types" "7.3.0"
"@sentry/utils" "7.3.0"
tslib "^1.9.3"

"@sentry/cli@^1.74.4":
Expand All @@ -3624,69 +3624,57 @@
proxy-from-env "^1.1.0"
which "^2.0.2"

"@sentry/core@6.19.7":
version "6.19.7"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.19.7.tgz#156aaa56dd7fad8c89c145be6ad7a4f7209f9785"
integrity sha512-tOfZ/umqB2AcHPGbIrsFLcvApdTm9ggpi/kQZFkej7kMphjT+SGBiQfYtjyg9jcRW+ilAR4JXC9BGKsdEQ+8Vw==
"@sentry/core@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.3.0.tgz#5e7c96efca254401dfc0e92f27cc9d4105bb0d52"
integrity sha512-EvuWVlYm0F0+BtIEmQiCL31Fw0cfKSwUTmxc99wvouaabpHBr2zCJHRxaXOWzxS705bYBJEQiFDTIHfoOQZMzA==
dependencies:
"@sentry/hub" "6.19.7"
"@sentry/minimal" "6.19.7"
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
"@sentry/hub" "7.3.0"
"@sentry/types" "7.3.0"
"@sentry/utils" "7.3.0"
tslib "^1.9.3"

"@sentry/hub@6.19.7":
version "6.19.7"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.19.7.tgz#58ad7776bbd31e9596a8ec46365b45cd8b9cfd11"
integrity sha512-y3OtbYFAqKHCWezF0EGGr5lcyI2KbaXW2Ik7Xp8Mu9TxbSTuwTe4rTntwg8ngPjUQU3SUHzgjqVB8qjiGqFXCA==
"@sentry/hub@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-7.3.0.tgz#ecb251b1191b503a7516e4f50503f096ac63e1c5"
integrity sha512-0GtTaWf/hoAMoIFY7Ke6eozIbG3FdIPM364sER4SxUQVSklp6AORrV6p82IgWPROK6aj83cPk9Bszgi6RiF/BA==
dependencies:
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
"@sentry/types" "7.3.0"
"@sentry/utils" "7.3.0"
tslib "^1.9.3"

"@sentry/[email protected]":
version "6.19.7"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.19.7.tgz#b3ee46d6abef9ef3dd4837ebcb6bdfd01b9aa7b4"
integrity sha512-wcYmSJOdvk6VAPx8IcmZgN08XTXRwRtB1aOLZm+MVHjIZIhHoBGZJYTVQS/BWjldsamj2cX3YGbGXNunaCfYJQ==
"@sentry/react@^7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-7.3.0.tgz#bcfa482f1385c974da88617693a0563f873fa0c8"
integrity sha512-0CqJSdJfRoVKeku9rLOJlkKPZ4McEkYLmAuIDonx3DO2oOMLkcJqAAQUdPi+zFDPnOfMJWxdHC1EaTT/r66lig==
dependencies:
"@sentry/hub" "6.19.7"
"@sentry/types" "6.19.7"
tslib "^1.9.3"

"@sentry/react@^6.11.0":
version "6.19.7"
resolved "https://registry.yarnpkg.com/@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"
"@sentry/browser" "7.3.0"
"@sentry/types" "7.3.0"
"@sentry/utils" "7.3.0"
hoist-non-react-statics "^3.3.2"
tslib "^1.9.3"

"@sentry/tracing@^6.11.0":
version "6.19.7"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.19.7.tgz#54bb99ed5705931cd33caf71da347af769f02a4c"
integrity sha512-ol4TupNnv9Zd+bZei7B6Ygnr9N3Gp1PUrNI761QSlHtPC25xXC5ssSD3GMhBgyQrcvpuRcCFHVNNM97tN5cZiA==
"@sentry/tracing@^7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-7.3.0.tgz#c3ab22eeec6c3f80ca1a4acee86c537cc3517cc7"
integrity sha512-A+mLEH8jtLkhfyw81EZA1XgI96jh9TIwH9EST3hdfSPgdZQf0A5sV8oVVh/d9Hw7NVb65Va5KhAZDNhcx5QxUA==
dependencies:
"@sentry/hub" "6.19.7"
"@sentry/minimal" "6.19.7"
"@sentry/types" "6.19.7"
"@sentry/utils" "6.19.7"
"@sentry/hub" "7.3.0"
"@sentry/types" "7.3.0"
"@sentry/utils" "7.3.0"
tslib "^1.9.3"

"@sentry/types@6.19.7":
version "6.19.7"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.19.7.tgz#c6b337912e588083fc2896eb012526cf7cfec7c7"
integrity sha512-jH84pDYE+hHIbVnab3Hr+ZXr1v8QABfhx39KknxqKWr2l0oEItzepV0URvbEhB446lk/S/59230dlUUIBGsXbg==
"@sentry/types@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.3.0.tgz#eb3b9dc0bd26503eab4a5a205f0b3889b2bf7c4f"
integrity sha512-cGkHdh9+uvbFTj65TjWcXuhe6vQiMY+U+N2GE5xCfmZT9hwuouCASViNsbJMpZqvCg+Yi0fasQLZ71rujiRNOA==

"@sentry/utils@6.19.7":
version "6.19.7"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.19.7.tgz#6edd739f8185fd71afe49cbe351c1bbf5e7b7c79"
integrity sha512-z95ECmE3i9pbWoXQrD/7PgkBAzJYR+iXtPuTkpBjDKs86O3mT+PXOT3BAn79w2wkn7/i3vOGD2xVr1uiMl26dA==
"@sentry/utils@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.3.0.tgz#d2970b26a75d30659dcc54ea632ba62fe9ded478"
integrity sha512-xUP8TBf2p/c6CN8eFQ7Y+xk0IFrJXsph5ScozqNl/2l/Xs8hd2EiYETqgUklphoYD4J2RxvPwMyqBL15QN6wNg==
dependencies:
"@sentry/types" "6.19.7"
"@sentry/types" "7.3.0"
tslib "^1.9.3"

"@sentry/webpack-plugin@^1.17.1":
Expand Down Expand Up @@ -13795,14 +13783,7 @@ is-color-stop@^1.0.0:
rgb-regex "^1.0.1"
rgba-regex "^1.0.0"

is-core-module@^2.0.0, is-core-module@^2.2.0, is-core-module@^2.8.1:
version "2.9.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69"
integrity sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==
dependencies:
has "^1.0.3"

is-core-module@^2.5.0:
is-core-module@^2.0.0, is-core-module@^2.2.0, is-core-module@^2.5.0, is-core-module@^2.8.1:
version "2.9.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69"
integrity sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==
Expand Down Expand Up @@ -20682,14 +20663,7 @@ semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semver@^6.3.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.2.1, semver@^7.3.2, semver@^7.3.5, semver@^7.3.7:
version "7.3.7"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
dependencies:
lru-cache "^6.0.0"

semver@^7.3.4:
semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7:
version "7.3.7"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
Expand Down