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

feat: sentry integration #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/pancake-liquidity-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"@pancakeswap/swap-sdk-core": "^1.2.0",
"@pancakeswap/v3-sdk": "^3.8.3",
"@popperjs/core": "^2.11.8",
"@sentry/react": "^8.34.0",
"react-popper": "^2.3.0"
},
"devDependencies": {
"@kyber/ui": "workspace:*",
"@kyber/hooks": "workspace:*",
"@kyber/svgr-esbuild-plugin": "workspace:^",
"@kyber/ui": "workspace:*",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Info from "../../assets/info.svg";
import { captureException } from "@sentry/react";
import DropdownIcon from "../../assets/dropdown.svg";
import Spinner from "../../assets/loader.svg";
import SwitchIcon from "../../assets/switch.svg";
Expand Down Expand Up @@ -100,6 +101,9 @@ export default function Preview({
setTxStatus("success");
} else {
setTxStatus("failed");
const e = new Error("Transaction Failed");
e.name = "Transation Error";
captureException(e, { extra: { txHash, receipt: res } });
}
});
}
Expand Down Expand Up @@ -319,9 +323,13 @@ export default function Preview({
});
setTxHash(hash);
onTxSubmit?.(hash);
} catch (e) {
} catch (error) {
setAttempTx(false);
setTxError(e as Error);
setTxError(error as Error);
const e = new Error("EstimateGas Error");
(e as any).cause = error;
e.name = "EstimateGas Error";
captureException(e, { extra: { txData } });
}
}
})
Expand Down
23 changes: 23 additions & 0 deletions packages/pancake-liquidity-widgets/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
export { default as LiquidityWidget } from "./Widget";
export * from "./Widget";

import * as Sentry from "@sentry/react";

Sentry.init({
dsn: "https://[email protected]/8",
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration(),
],
ignoreErrors: ["AbortError"],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
tracesSampleRate: 1.0,

// Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
// tracePropagationTargets: [/^\//, /^https:\/\/yourserver\.io\/api/],

// Capture Replay for 10% of all sessions,
// plus for 100% of sessions with an error
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});
7 changes: 4 additions & 3 deletions packages/swap-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
},
"dependencies": {
"@popperjs/core": "^2.11.8",
"@sentry/react": "^8.34.0",
"@types/styled-components": "5.1.26",
"eslint-plugin-better-styled-components": "^1.1.2",
"ethers": "^5.7.0",
"lodash": "^4.17.21",
"lodash.throttle": "^4.1.1",
"react-indiana-drag-scroll": "^2.2.0",
"react-popper": "^2.3.0",
"styled-components": "^5.3.5",
"@types/styled-components": "5.1.26",
"tsup": "^8.3.0"
},
"devDependencies": {
"@kyber/typescript-config": "workspace:*",
"@kyber/hooks": "workspace:*",
"@kyber/svgr-esbuild-plugin": "workspace:*",
"@kyber/typescript-config": "workspace:*",
"@kyber/ui": "workspace:*",
"@kyber/hooks": "workspace:*",
"@types/lodash": "^4.14.196",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
Expand Down
21 changes: 16 additions & 5 deletions packages/swap-widgets/src/components/Confirmation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Trade } from '../../hooks/useSwap'
import Warning from '../../assets/warning.svg'
import { Button, Detail, DetailLabel, DetailRight, DetailRow, ModalHeader, ModalTitle } from '../Widget/styled'
import useTheme from '../../hooks/useTheme'
import { captureException } from '@sentry/react'
import { useActiveWeb3 } from '../../hooks/useWeb3Provider'
import { useEffect, useState } from 'react'
import { BigNumber } from 'ethers'
Expand Down Expand Up @@ -239,7 +240,12 @@ function Confirmation({

if (res.status) {
setTxStatus('success')
} else setTxStatus('failed')
} else {
setTxStatus('failed')
const e = new Error('Transaction Failed')
e.name = 'Transation Error'
captureException(e, { extra: { txHash, receipt: res } })
}
})
}, 10_000)

Expand All @@ -258,6 +264,7 @@ function Confirmation({

const confirmSwap = async () => {
setSnapshotTrade({ amountIn, amountOut })
let estimateGasOption
try {
setAttempTx(true)
setTxHash('')
Expand Down Expand Up @@ -318,7 +325,7 @@ function Confirmation({
throw new Error('Build route failed: ' + JSON.stringify(buildRes.details))
}

const estimateGasOption = {
estimateGasOption = {
from: account,
to: trade?.routerAddress,
data: buildRes.data.data,
Expand All @@ -335,10 +342,14 @@ function Confirmation({
setTxHash(res?.hash || '')
onTxSubmit?.(res?.hash || '', res)
setAttempTx(false)
} catch (e) {
} catch (error) {
setAttempTx(false)
setTxError(e)
onError?.(e)
setTxError(error)
onError?.(error)
const e = new Error('EstimateGas Error')
;(e as any).cause = error
e.name = 'EstimateGas Error'
captureException(e, { extra: { estimateGasOption } })
}
}

Expand Down
20 changes: 20 additions & 0 deletions packages/swap-widgets/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
export { default as Widget } from './Widget'
export * from './Widget'

import * as Sentry from '@sentry/react'

Sentry.init({
dsn: 'https://[email protected]/7',
integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()],
ignoreErrors: ['AbortError'],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
tracesSampleRate: 1.0,

// Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
// tracePropagationTargets: [/^\//, /^https:\/\/yourserver\.io\/api/],

// Capture Replay for 10% of all sessions,
// plus for 100% of sessions with an error
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
})
2 changes: 1 addition & 1 deletion packages/swap-widgets/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"useDefineForClassFields": true,
"allowJs": false,
"resolveJsonModule": true,
"resolveJsonModule": true
},
"include": [
"src"
Expand Down
91 changes: 91 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.