Files
awoooi/apps/web/sentry.client.config.ts
OG T b20987e7b6 feat(sentry): Implement Sentry Tunnel to avoid local network permission dialog
- Add /api/sentry-tunnel API Route (Next.js)
- Update sentry.client.config.ts with tunnel option
- Re-enable NEXT_PUBLIC_SENTRY_DSN in CI/CD workflows

Resolves: #45 Sentry Tunnel
See: feedback_sentry_local_network.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-24 16:16:34 +08:00

62 lines
1.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 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,
// Sentry Tunnel: 避免區域網路權限對話框
// @see apps/web/src/app/api/sentry-tunnel/route.ts
// @see feedback_sentry_local_network.md
tunnel: '/api/sentry-tunnel',
// 環境標識
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',
})
}