From 397fe5f28b1cb3bc5517a8b30ed464a7266b5b45 Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Sat, 23 Dec 2023 16:51:19 +0100 Subject: [PATCH] Refactor: remove Sentry performance tracing (#3052) --- next.config.mjs | 2 +- package.json | 3 +- .../safe-apps/AppFrame/useAppCommunicator.ts | 9 +- src/pages/_app.tsx | 6 +- .../exceptions/__tests__/index.test.ts | 34 +---- src/services/exceptions/index.ts | 14 +- src/services/sentry.ts | 9 +- yarn.lock | 126 +++++++++--------- 8 files changed, 87 insertions(+), 116 deletions(-) diff --git a/next.config.mjs b/next.config.mjs index 07d1f2a35d..78f1bb9b2a 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -32,7 +32,7 @@ const nextConfig = { dirs: ['src'], }, experimental: { - optimizePackageImports: ['@mui/material', '@mui/icons-material', 'lodash', 'date-fns'], + optimizePackageImports: ['@mui/material', '@mui/icons-material', 'lodash', 'date-fns', '@sentry/react'], }, webpack(config) { config.module.rules.push({ diff --git a/package.json b/package.json index 1df30d7814..6a589a12b1 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,7 @@ "@safe-global/safe-ethers-lib": "^1.9.4", "@safe-global/safe-gateway-typescript-sdk": "^3.13.3", "@safe-global/safe-modules-deployments": "^1.2.0", - "@sentry/react": "^7.74.0", - "@sentry/tracing": "^7.74.0", + "@sentry/react": "^7.91.0", "@spindl-xyz/attribution-lite": "^1.4.0", "@tkey-mpc/common-types": "^8.2.2", "@truffle/hdwallet-provider": "^2.1.4", diff --git a/src/components/safe-apps/AppFrame/useAppCommunicator.ts b/src/components/safe-apps/AppFrame/useAppCommunicator.ts index 74059b1e74..b1b015943f 100644 --- a/src/components/safe-apps/AppFrame/useAppCommunicator.ts +++ b/src/components/safe-apps/AppFrame/useAppCommunicator.ts @@ -103,13 +103,8 @@ const useAppCommunicator = ( }, ) }, - onError: (error, data) => { - logError(Errors._901, error.message, { - contexts: { - safeApp: app || {}, - request: data, - }, - }) + onError: (error) => { + logError(Errors._901, error.message) }, }) diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index d49e4a5643..9fd5406ec1 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,6 +1,6 @@ +import { SentryErrorBoundary } from '@/services/sentry' // needs to be imported first import useRehydrateSocialWallet from '@/hooks/wallets/mpc/useRehydrateSocialWallet' import PasswordRecoveryModal from '@/services/mpc/PasswordRecoveryModal' -import Sentry from '@/services/sentry' // needs to be imported first import type { ReactNode } from 'react' import { type ReactElement } from 'react' import { type AppProps } from 'next/app' @@ -79,11 +79,11 @@ export const AppProviders = ({ children }: { children: ReactNode | ReactNode[] } {(safeTheme: Theme) => ( - + {children} - + )} diff --git a/src/services/exceptions/__tests__/index.test.ts b/src/services/exceptions/__tests__/index.test.ts index bf87971a20..72752cc424 100644 --- a/src/services/exceptions/__tests__/index.test.ts +++ b/src/services/exceptions/__tests__/index.test.ts @@ -1,16 +1,15 @@ import { Errors, logError, trackError, CodedException } from '..' import * as constants from '@/config/constants' -import * as Sentry from '@sentry/react' +import * as Sentry from '@/services/sentry' + +jest.spyOn(Sentry, 'sentryCaptureException').mockImplementation(() => '') describe('CodedException', () => { beforeAll(() => { - jest.mock('@sentry/react') jest.mock('@/config/constants', () => ({ IS_PRODUCTION: false, })) console.error = jest.fn() - // @ts-ignore - Sentry.captureException = jest.fn() }) afterAll(() => { @@ -58,31 +57,12 @@ describe('CodedException', () => { expect(err.content).toBe(Errors._100) }) - it('creates an error with an extra message and a context', () => { - const context = { - tags: { - error_category: 'Safe Apps', - }, - contexts: { - safeApp: { - name: 'Zorbed.Finance', - url: 'https://zorbed.finance', - }, - message: { - method: 'getSafeBalance', - params: { - address: '0x000000', - }, - }, - }, - } - - const err = new CodedException(Errors._901, 'getSafeBalance: Server responded with 429 Too Many Requests', context) + it('creates an error with an extra message', () => { + const err = new CodedException(Errors._901, 'getSafeBalance: Server responded with 429 Too Many Requests') expect(err.message).toBe( 'Code 901: Error processing Safe Apps SDK request (getSafeBalance: Server responded with 429 Too Many Requests)', ) expect(err.code).toBe(901) - expect(err.context).toEqual(context) }) describe('Logging', () => { @@ -111,13 +91,13 @@ describe('CodedException', () => { it('tracks using Sentry on production', () => { jest.spyOn(constants, 'IS_PRODUCTION', 'get').mockImplementation(() => true) const err = trackError(Errors._100) - expect(Sentry.captureException).toHaveBeenCalled() + expect(Sentry.sentryCaptureException).toHaveBeenCalled() expect(console.error).toHaveBeenCalledWith(err.message) }) it('does not track using Sentry in non-production envs', () => { const err = trackError(Errors._100) - expect(Sentry.captureException).not.toHaveBeenCalled() + expect(Sentry.sentryCaptureException).not.toHaveBeenCalled() expect(console.error).toHaveBeenCalledWith(err) }) }) diff --git a/src/services/exceptions/index.ts b/src/services/exceptions/index.ts index 9db26380c0..5166028b2b 100644 --- a/src/services/exceptions/index.ts +++ b/src/services/exceptions/index.ts @@ -1,5 +1,4 @@ -import * as Sentry from '@sentry/react' -import type { CaptureContext } from '@sentry/types' +import { sentryCaptureException } from '@/services/sentry' import { IS_PRODUCTION } from '@/config/constants' import ErrorCodes from './ErrorCodes' import { asError } from './utils' @@ -7,10 +6,6 @@ import { asError } from './utils' export class CodedException extends Error { public readonly code: number public readonly content: string - // the context allows to enrich events, for the list of allowed context keys/data, please check the type or go to - // https://docs.sentry.io/platforms/javascript/enriching-events/context/ - // The context is not searchable, that means its goal is just to provide additional data for the error - public readonly context?: CaptureContext private getCode(content: ErrorCodes): number { const codePrefix = content.split(':')[0] @@ -21,14 +16,13 @@ export class CodedException extends Error { return code } - constructor(content: ErrorCodes, thrown?: unknown, context?: CaptureContext) { + constructor(content: ErrorCodes, thrown?: unknown) { super() const extraInfo = thrown ? ` (${asError(thrown).message})` : '' this.message = `Code ${content}${extraInfo}` this.code = this.getCode(content) this.content = content - this.context = context } public log(): void { @@ -51,12 +45,12 @@ export class CodedException extends Error { this.log() if (IS_PRODUCTION) { - Sentry.captureException(this, this.context) + sentryCaptureException(this) } } } -type ErrorHandler = (content: ErrorCodes, thrown?: unknown, context?: CaptureContext) => CodedException +type ErrorHandler = (content: ErrorCodes, thrown?: unknown) => CodedException export const logError: ErrorHandler = function logError(...args) { const error = new CodedException(...args) diff --git a/src/services/sentry.ts b/src/services/sentry.ts index 6ddb946361..a86e515c1e 100644 --- a/src/services/sentry.ts +++ b/src/services/sentry.ts @@ -1,12 +1,10 @@ -import * as Sentry from '@sentry/react' -import { Integrations } from '@sentry/tracing' +import { init, ErrorBoundary, captureException } from '@sentry/react' import { SENTRY_DSN } from '@/config/constants' import packageJson from '../../package.json' -Sentry.init({ +init({ dsn: SENTRY_DSN, release: `safe-wallet-web@${packageJson.version}`, - integrations: [new Integrations.BrowserTracing()], sampleRate: 0.1, // ignore MetaMask errors we don't control ignoreErrors: ['Internal JSON-RPC error', 'JsonRpcEngine', 'Non-Error promise rejection captured with keys: code'], @@ -26,4 +24,5 @@ Sentry.init({ }, }) -export default Sentry +export const SentryErrorBoundary = ErrorBoundary +export const sentryCaptureException = captureException diff --git a/yarn.lock b/yarn.lock index 2d34dd6b16..0c6d7aab42 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4010,76 +4010,80 @@ "@noble/hashes" "~1.3.0" "@scure/base" "~1.1.0" -"@sentry-internal/tracing@7.74.0": - version "7.74.0" - resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.74.0.tgz#11b0762d0b18b01cc18dfb1e40bbaa41c6f97452" - integrity sha512-JK6IRGgdtZjswGfaGIHNWIThffhOHzVIIaGmglui+VFIzOsOqePjoxaDV0MEvzafxXZD7eWqGE5RGuZ0n6HFVg== - dependencies: - "@sentry/core" "7.74.0" - "@sentry/types" "7.74.0" - "@sentry/utils" "7.74.0" - tslib "^2.4.1 || ^1.9.3" - -"@sentry/browser@7.74.0": - version "7.74.0" - resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.74.0.tgz#4a01bccb34059894007b9a22a89892f2c4dff130" - integrity sha512-Njr8216Z1dFUcl6NqBOk20dssK9SjoVddY74Xq+Q4p3NfXBG3lkMcACXor7SFoJRZXq8CZWGS13Cc5KwViRw4g== - dependencies: - "@sentry-internal/tracing" "7.74.0" - "@sentry/core" "7.74.0" - "@sentry/replay" "7.74.0" - "@sentry/types" "7.74.0" - "@sentry/utils" "7.74.0" - tslib "^2.4.1 || ^1.9.3" - -"@sentry/core@7.74.0": - version "7.74.0" - resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.74.0.tgz#2cfcb5133a4a3f82fbac09d3573ea9f508fb7c67" - integrity sha512-83NRuqn7nDZkSVBN5yJQqcpXDG4yMYiB7TkYUKrGTzBpRy6KUOrkCdybuKk0oraTIGiGSe5WEwCFySiNgR9FzA== - dependencies: - "@sentry/types" "7.74.0" - "@sentry/utils" "7.74.0" - tslib "^2.4.1 || ^1.9.3" - -"@sentry/react@^7.74.0": - version "7.74.0" - resolved "https://registry.yarnpkg.com/@sentry/react/-/react-7.74.0.tgz#11e63e7f99cc60fa8c2846d929aa7dc0f0769e77" - integrity sha512-w5VODhLM8Kva2ZscGzgwLgkAi0TY+/Ht9SxdKlGFBJU9r7LllqzuGQ5HUcw9CPsQJnrL8VNdq8ngJPE1YbAUqw== - dependencies: - "@sentry/browser" "7.74.0" - "@sentry/types" "7.74.0" - "@sentry/utils" "7.74.0" +"@sentry-internal/feedback@7.91.0": + version "7.91.0" + resolved "https://registry.yarnpkg.com/@sentry-internal/feedback/-/feedback-7.91.0.tgz#be09e5aec2959fcf503e2cf78496d5e2d263bc5a" + integrity sha512-SJKTSaz68F5YIwF79EttBm915M2LnacgZMYRnRumyTmMKnebGhYQLwWbZdpaDvOa1U18dgRajDX8Qed/8A3tXw== + dependencies: + "@sentry/core" "7.91.0" + "@sentry/types" "7.91.0" + "@sentry/utils" "7.91.0" + +"@sentry-internal/tracing@7.91.0": + version "7.91.0" + resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.91.0.tgz#fbb6e1e3383e1eeee08633384e004da73ac1c37d" + integrity sha512-JH5y6gs6BS0its7WF2DhySu7nkhPDfZcdpAXldxzIlJpqFkuwQKLU5nkYJpiIyZz1NHYYtW5aum2bV2oCOdDRA== + dependencies: + "@sentry/core" "7.91.0" + "@sentry/types" "7.91.0" + "@sentry/utils" "7.91.0" + +"@sentry/browser@7.91.0": + version "7.91.0" + resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.91.0.tgz#de3b9ae3ca7716a35cfabc97ac376944a67e6e34" + integrity sha512-lJv3x/xekzC/biiyAsVCioq2XnKNOZhI6jY3ZzLJZClYV8eKRi7D3KCsHRvMiCdGak1d/6sVp8F4NYY+YiWy1Q== + dependencies: + "@sentry-internal/feedback" "7.91.0" + "@sentry-internal/tracing" "7.91.0" + "@sentry/core" "7.91.0" + "@sentry/replay" "7.91.0" + "@sentry/types" "7.91.0" + "@sentry/utils" "7.91.0" + +"@sentry/core@7.91.0": + version "7.91.0" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.91.0.tgz#229334d7f03dd5d90a17495e61ce4215ab730b2a" + integrity sha512-tu+gYq4JrTdrR+YSh5IVHF0fJi/Pi9y0HZ5H9HnYy+UMcXIotxf6hIEaC6ZKGeLWkGXffz2gKpQLe/g6vy/lPA== + dependencies: + "@sentry/types" "7.91.0" + "@sentry/utils" "7.91.0" + +"@sentry/react@^7.91.0": + version "7.91.0" + resolved "https://registry.yarnpkg.com/@sentry/react/-/react-7.91.0.tgz#620e6ce9452af025d2cc1b2eca3dd1dd730dc439" + integrity sha512-7JH2rWaX3WKHHvBcZQ4f/KnkYIXTf7hMojRFncUwPocdtDlhJw/JUvjAYNpEysixXIgsMes3B32lmtZjGjRhwQ== + dependencies: + "@sentry/browser" "7.91.0" + "@sentry/types" "7.91.0" + "@sentry/utils" "7.91.0" hoist-non-react-statics "^3.3.2" - tslib "^2.4.1 || ^1.9.3" -"@sentry/replay@7.74.0": - version "7.74.0" - resolved "https://registry.yarnpkg.com/@sentry/replay/-/replay-7.74.0.tgz#618d40f7c9ecc7589dd14df0c560b20a24839d3f" - integrity sha512-GoYa3cHTTFVI/J1cnZ0i4X128mf/JljaswO3PWNTe2k3lSHq/LM5aV0keClRvwM0W8hlix8oOTT06nnenOUmmw== +"@sentry/replay@7.91.0": + version "7.91.0" + resolved "https://registry.yarnpkg.com/@sentry/replay/-/replay-7.91.0.tgz#95077868aee3c3cc670affe13156434f858e1755" + integrity sha512-XwbesnLLNtaVXKtDoyBB96GxJuhGi9zy3a662Ba/McmumCnkXrMQYpQPh08U7MgkTyDRgjDwm7PXDhiKpcb03g== dependencies: - "@sentry/core" "7.74.0" - "@sentry/types" "7.74.0" - "@sentry/utils" "7.74.0" + "@sentry-internal/tracing" "7.91.0" + "@sentry/core" "7.91.0" + "@sentry/types" "7.91.0" + "@sentry/utils" "7.91.0" -"@sentry/tracing@^7.74.0": - version "7.74.0" - resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-7.74.0.tgz#8d9aee19f448d3635abddd5fe86248bc0b89c8ac" - integrity sha512-rSFJADhh3J3zmkzJ1EXCOwS3h7F6o/lSKu7CWZSZ6k5kBvbCJ5AXvGQadhPdWPJMMcPFzCJaOyTKEPcwL4tbCw== - dependencies: - "@sentry-internal/tracing" "7.74.0" +"@sentry/types@7.91.0": + version "7.91.0" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.91.0.tgz#5b68954e08986fecb0d4bef168df58eef62c32c7" + integrity sha512-bcQnb7J3P3equbCUc+sPuHog2Y47yGD2sCkzmnZBjvBT0Z1B4f36fI/5WjyZhTjLSiOdg3F2otwvikbMjmBDew== -"@sentry/types@7.74.0", "@sentry/types@^7.74.0": +"@sentry/types@^7.74.0": version "7.74.0" resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.74.0.tgz#810a62cd28db21c5f15f131da6525d7ddf7a29db" integrity sha512-rI5eIRbUycWjn6s6o3yAjjWtIvYSxZDdnKv5je2EZINfLKcMPj1dkl6wQd2F4y7gLfD/N6Y0wZYIXC3DUdJQQg== -"@sentry/utils@7.74.0": - version "7.74.0" - resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.74.0.tgz#e0a16d345b2af6f8b09d157c8c8a3145d7a2070a" - integrity sha512-k3np8nuTPtx5KDODPtULfFln4UXdE56MZCcF19Jv6Ljxf+YN/Ady1+0Oi3e0XoSvFpWNyWnglauT7M65qCE6kg== +"@sentry/utils@7.91.0": + version "7.91.0" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.91.0.tgz#3b1a94c053c885877908cd3e1365e3d23e21a73f" + integrity sha512-fvxjrEbk6T6Otu++Ax9ntlQ0sGRiwSC179w68aC3u26Wr30FAIRKqHTCCdc2jyWk7Gd9uWRT/cq+g8NG/8BfSg== dependencies: - "@sentry/types" "7.74.0" - tslib "^2.4.1 || ^1.9.3" + "@sentry/types" "7.91.0" "@sideway/address@^4.1.3": version "4.1.4" @@ -15156,7 +15160,7 @@ tslib@1.14.1, tslib@^1.8.1, tslib@^1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@^2.0.0, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.4.0, "tslib@^2.4.1 || ^1.9.3": +tslib@^2.0.0, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.4.0: version "2.6.2" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae" integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==