f1191299e8
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.
24 lines
755 B
TypeScript
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}</>;
|
|
}
|