/** * Sentry Client Configuration * =========================== * 前端錯誤追蹤與效能監控 * * 部署: Self-Hosted @ 192.168.0.110 * 整合策略: 補強 SignOz,專注 Error Tracking + Session Replay */ import * as Sentry from '@sentry/nextjs' // 只在有 DSN 時初始化 (環境變數控制) if (process.env.NEXT_PUBLIC_SENTRY_DSN) { Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, // 環境標識 environment: process.env.NODE_ENV, // 效能監控取樣率 (生產環境降低以節省資源) tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.2 : 1.0, // Session Replay 設定 (Sentry 獨家功能) replaysSessionSampleRate: 0.1, // 10% 隨機 session replaysOnErrorSampleRate: 1.0, // 100% 錯誤 session // 整合設定 integrations: [ Sentry.replayIntegration({ // 隱私保護: 遮蔽敏感資料 maskAllText: false, maskAllInputs: true, blockAllMedia: false, }), Sentry.browserTracingIntegration(), ], // 忽略常見的非錯誤 ignoreErrors: [ // 網路錯誤 (使用者網路問題) 'Failed to fetch', 'NetworkError', 'Load failed', // 瀏覽器擴充套件 'ResizeObserver loop limit exceeded', // 第三方腳本 /^Script error\.?$/, ], // 只在生產環境發送 enabled: process.env.NODE_ENV === 'production', // Debug 模式 (開發時啟用) debug: process.env.NODE_ENV === 'development', }) }