From fb3bba897f844e9f51dc1158909ac541f91c18c9 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 8 Apr 2022 18:14:00 -0500 Subject: [PATCH] =?UTF-8?q?build:=20=F0=9F=91=B7=20Add=20Sentry=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/builder/contexts/UserContext.tsx | 5 ++++- apps/builder/sentry.client.config.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/builder/contexts/UserContext.tsx b/apps/builder/contexts/UserContext.tsx index 16f64462a27..c3d5e1d3260 100644 --- a/apps/builder/contexts/UserContext.tsx +++ b/apps/builder/contexts/UserContext.tsx @@ -13,6 +13,7 @@ import { updateUser as updateUserInDb } from 'services/user/user' import { useToast } from '@chakra-ui/react' import { dequal } from 'dequal' import { User } from 'db' +import { setUser as setSentryUser } from '@sentry/nextjs' const userContext = createContext<{ user?: User @@ -48,7 +49,9 @@ export const UserContext = ({ children }: { children: ReactNode }) => { useEffect(() => { if (isDefined(user) || isNotDefined(session)) return - setUser(session.user as User) + const parsedUser = session.user as User + setUser(parsedUser) + setSentryUser({ id: parsedUser.id }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [session]) diff --git a/apps/builder/sentry.client.config.js b/apps/builder/sentry.client.config.js index f6bd94b707a..5eae2a0dd6d 100644 --- a/apps/builder/sentry.client.config.js +++ b/apps/builder/sentry.client.config.js @@ -7,4 +7,14 @@ import * as Sentry from '@sentry/nextjs' Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, ignoreErrors: ['ResizeObserver loop limit exceeded'], + beforeBreadcrumb(breadcrumb, hint) { + try { + if (breadcrumb.category?.startsWith('ui')) { + breadcrumb.message = `${hint?.event.target.tagName.toLowerCase()}: ${ + hint?.event.target.innerText + }` + } + } catch (e) {} + return breadcrumb + }, })