Files
eranos/src/components/SentryProvider.tsx
T
Alex Gleason f1191299e8 Add Sentry integration with lazy loading and user-configurable DSN
Sentry SDK is loaded via dynamic import() only when a DSN is configured
and error reporting is enabled, keeping it out of the initial bundle.
Users can control error reporting via a toggle and DSN field in
Advanced Settings, with the DSN synced across devices via encrypted
NIP-78 settings. The ErrorBoundary now reports fatal crashes to Sentry
with component stack context, and a beforeSend hook censors nsec
private keys before any data leaves the browser.
2026-03-03 17:25:14 -06:00

24 lines
755 B
TypeScript

import { ReactNode, useEffect } from 'react';
import { useAppContext } from '@/hooks/useAppContext';
import { initializeSentry, disableSentry, isSentryInitialized } from '@/lib/sentry';
interface SentryProviderProps {
children: ReactNode;
}
export function SentryProvider({ children }: SentryProviderProps) {
const { config } = useAppContext();
useEffect(() => {
const shouldEnableSentry = config.sentryDsn && config.sentryEnabled;
if (shouldEnableSentry && !isSentryInitialized()) {
initializeSentry(config.sentryDsn).catch(console.error);
} else if (!shouldEnableSentry && isSentryInitialized()) {
disableSentry().catch(console.error);
}
}, [config.sentryDsn, config.sentryEnabled]);
return <>{children}</>;
}