Skip to content

Commit

Permalink
[SENTRY] Add chainId tag and user to context (#751)
Browse files Browse the repository at this point in the history
* fix

* add new chainId tag and user

* update sentry

* properly handle SellAmountDoesNotCoverFee

* pr comments

* edit tags

* remove comment

* UNKNOWN enum

* simplify logic

* export type
  • Loading branch information
W3stside authored Jun 29, 2022
1 parent 8b67bf2 commit b285c2a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 77 deletions.
4 changes: 2 additions & 2 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",
"@sentry/webpack-plugin": "^1.17.1",
"@uniswap/redux-multicall": "^1.1.1",
"@uniswap/router-sdk": "^1.0.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
70 changes: 55 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,84 @@ 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'

export 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 {
// match connectedChainId type
const appChainNormalised = appChainId ?? undefined

let sentryChainId
if (connectedChainId) {
// user is browsing app disconnected from wallet
sentryChainId = connectedChainId
} else {
// connectedChainId takes precedence
sentryChainId = appChainNormalised
}

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

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 = _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)
// connectivity tag
scope.setTag('walletConnected', !!account)
// 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
100 changes: 44 additions & 56 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

0 comments on commit b285c2a

Please sign in to comment.