From b86f3f1c0b830a1c2f955c43e731800598bc5a0c Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Mon, 2 Jun 2025 14:38:34 -0500 Subject: [PATCH 1/3] [CORE-999] add user data to Sentry init --- src/components/ErrorBoundary.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index 8b4e5c42..437d815b 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -47,6 +47,8 @@ export const ErrorBoundary = ({ // Optionally re-render with the children so they can display inline errors with const renderElement = error && renderFallback ? (typedFallback || fallback) : <>{children}; + type WindowWithUserData = Window & { _OX_USER_DATA?: string } + React.useEffect(() => { if (!sentryDsn && !sentryInit) { return; @@ -59,6 +61,9 @@ export const ErrorBoundary = ({ Sentry.init(sentryInit || { dsn: sentryDsn, environment: window.location.hostname, + initialScope: { + tags: { userData: (window as WindowWithUserData)._OX_USER_DATA } + }, integrations: [ Sentry.browserTracingIntegration(), Sentry.extraErrorDataIntegration() From 41da1ae4077a2e28a63af258724e02fc8c865237 Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Tue, 3 Jun 2025 09:55:11 -0500 Subject: [PATCH 2/3] Use the correct type and send just the uuid --- src/components/ErrorBoundary.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index 437d815b..d2e51906 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -5,6 +5,7 @@ import type { ErrorBoundaryProps } from '@sentry/react/types/errorboundary'; import { ErrorContext } from '../contexts'; import { SentryError } from '../types'; import { getTypeFromError } from '../utils'; +import type { User } from '@openstax/ts-utils/services/authProvider'; const Error = ({ children, ...props }: React.PropsWithChildren) => {children}; @@ -47,7 +48,7 @@ export const ErrorBoundary = ({ // Optionally re-render with the children so they can display inline errors with const renderElement = error && renderFallback ? (typedFallback || fallback) : <>{children}; - type WindowWithUserData = Window & { _OX_USER_DATA?: string } + type WindowWithUserData = Window & { _OX_USER_DATA?: User } React.useEffect(() => { if (!sentryDsn && !sentryInit) { @@ -62,7 +63,7 @@ export const ErrorBoundary = ({ dsn: sentryDsn, environment: window.location.hostname, initialScope: { - tags: { userData: (window as WindowWithUserData)._OX_USER_DATA } + tags: { userData: (window as WindowWithUserData)._OX_USER_DATA?.uuid } }, integrations: [ Sentry.browserTracingIntegration(), From 2668baedf0549ee186ea84968b20b31252a0be6b Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Fri, 6 Jun 2025 17:18:34 -0500 Subject: [PATCH 3/3] pass data as user.uuid --- src/components/ErrorBoundary.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index d2e51906..ce7dd2f6 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -63,7 +63,7 @@ export const ErrorBoundary = ({ dsn: sentryDsn, environment: window.location.hostname, initialScope: { - tags: { userData: (window as WindowWithUserData)._OX_USER_DATA?.uuid } + user: { uuid: (window as WindowWithUserData)._OX_USER_DATA?.uuid }, }, integrations: [ Sentry.browserTracingIntegration(),