From a7d78d0935de2f6acad01ab581b3df01894bef35 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 21 Oct 2023 14:18:56 -0500 Subject: [PATCH] Delete monitoring.ts, add `captureSentryException` to sentry.ts --- src/components/error-boundary.tsx | 4 ++-- src/monitoring.ts | 13 ------------- src/sentry.ts | 9 ++++++++- 3 files changed, 10 insertions(+), 16 deletions(-) delete mode 100644 src/monitoring.ts diff --git a/src/components/error-boundary.tsx b/src/components/error-boundary.tsx index b25ca2aae..225b64023 100644 --- a/src/components/error-boundary.tsx +++ b/src/components/error-boundary.tsx @@ -5,7 +5,7 @@ import { connect } from 'react-redux'; import { getSoapboxConfig } from 'soapbox/actions/soapbox'; import * as BuildConfig from 'soapbox/build-config'; import { HStack, Text, Stack } from 'soapbox/components/ui'; -import { captureException } from 'soapbox/monitoring'; +import { captureSentryException } from 'soapbox/sentry'; import KVStore from 'soapbox/storage/kv-store'; import sourceCode from 'soapbox/utils/code'; import { unregisterSW } from 'soapbox/utils/sw'; @@ -37,7 +37,7 @@ class ErrorBoundary extends React.PureComponent { textarea: HTMLTextAreaElement | null = null; componentDidCatch(error: any, info: any): void { - captureException(error, { + captureSentryException(error, { tags: { // Allow page crashes to be easily searched in Sentry. ErrorBoundary: 'yes', diff --git a/src/monitoring.ts b/src/monitoring.ts deleted file mode 100644 index 128b3a5ba..000000000 --- a/src/monitoring.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { CaptureContext } from '@sentry/types'; - -/** Capture the exception and report it to Sentry. */ -async function captureException (exception: any, captureContext?: CaptureContext | undefined): Promise { - try { - const Sentry = await import('@sentry/react'); - Sentry.captureException(exception, captureContext); - } catch (e) { - console.error(e); - } -} - -export { captureException }; diff --git a/src/sentry.ts b/src/sentry.ts index b5617c324..31cec656b 100644 --- a/src/sentry.ts +++ b/src/sentry.ts @@ -2,6 +2,7 @@ import { NODE_ENV } from 'soapbox/build-config'; import sourceCode from 'soapbox/utils/code'; import type { Account } from './schemas'; +import type { CaptureContext } from '@sentry/types'; /** Start Sentry. */ async function startSentry(dsn: string): Promise { @@ -63,4 +64,10 @@ async function unsetSentryAccount() { Sentry.setUser(null); } -export { startSentry, setSentryAccount, unsetSentryAccount }; \ No newline at end of file +/** Capture the exception and report it to Sentry. */ +async function captureSentryException (exception: any, captureContext?: CaptureContext | undefined): Promise { + const Sentry = await import('@sentry/react'); + Sentry.captureException(exception, captureContext); +} + +export { startSentry, setSentryAccount, unsetSentryAccount, captureSentryException }; \ No newline at end of file