Files
novalon-website/src/instrumentation-client.ts
T
zhangxiang a366bd1400 fix(qa): 第五轮系统性质量保障缺陷修复 + 单元/集成测试
安全/鉴权:登出清服务端 httpOnly 令牌、登录 IP 限流前置 bcrypt、停用账号
令牌在 6 个内联 role handler 失效、admin/items 存在性 oracle 认证前置、
同意偏好 sanitize fail-closed、api-crypto 按 HTTP 方法判体。

CMS:workflow 状态更新+审计收进交互式 $transaction(失败即回滚)、编辑器
richtext 走 textarea 防换行损毁、array/object 子字段按作用域读写防污染、
about/contact/erp-upgrade 补 ISR revalidate 与路由映射。

UI/a11y:AnimatedCounter 入视口前显起点、CLS 累计上报、MetricCard 动画入
effect 并卸载取消 rAF、后台状态四态映射/搜索防抖+序号守卫/媒体单 input/
吞错改横幅/表单 label-aria 关联。

新增对应判别性单测与 pagination/rate-limit/client-ip/sanitize/validate-content-data
等模块及 tests-integration 真库集成层。
2026-09-28 10:48:07 +08:00

95 lines
3.5 KiB
TypeScript
Raw 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.
import * as Sentry from '@sentry/nextjs';
/**
* 客户端 Sentry 初始化入口。原 sentry.client.config.ts 的内容整体迁移至此,原因(佐证来自已安装版本源码):
* - Next 16 起 `next build` 默认使用 Turbopack
* (node_modules/next/dist/docs/01-app/02-guides/upgrading/version-16.md:128),
* 而 SDK 明确警告 sentry.client.config.ts 在 Turbopack 下不再被加载:
* node_modules/@sentry/nextjs/build/esm/config/webpack.js:207-213
* ("renaming your sentry.client.config.ts file, or moving its content to instrumentation-client.ts")
* - instrumentation-client.ts 是 Next 官方客户端入口约定:在 HTML 加载后、React hydration 前执行,
* 且仅顶层同步代码保证在 hydration 前完成 —— 因此本文件顶层直接同步调用 Sentry.init:
* node_modules/next/dist/docs/01-app/03-api-reference/03-file-conventions/instrumentation-client.md(Usage / Execution timing 两节)
* - 路由导航插桩要求导出 onRouterTransitionStart = Sentry.captureRouterTransitionStart,否则构建期告警:
* node_modules/@sentry/nextjs/build/esm/config/withSentryConfig/getFinalConfigObjectUtils.js:131-137;
* captureRouterTransitionStart 见 node_modules/@sentry/nextjs/build/types/client/index.d.ts:8
*
* 无 DSN 门禁与 GA(GoogleAnalytics.tsx 无 ID 即返回 null)同一约定:NEXT_PUBLIC_SENTRY_DSN 为空时
* 跳过 Sentry.init,SDK 保持惰性、不发任何请求。
*/
const SENTRY_DSN = process.env.NEXT_PUBLIC_SENTRY_DSN || '';
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,
environment: process.env.NODE_ENV || 'development',
enabled: process.env.NODE_ENV !== 'development',
tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.2 : 0,
replaysSessionSampleRate: 0,
replaysOnErrorSampleRate: 1.0,
ignoreErrors: [
/_AutofillCallbackHandler/,
/NetworkError/,
/webkit\.messageHandlers/,
/Non-Error promise rejection captured/,
/^Loading CSS chunk.*failed/,
/^Loading chunk.*failed/,
/^Failed to fetch dynamically imported module/,
],
denyUrls: [
/extensions\//i,
/^chrome:\/\//i,
/webappstoolbars/i,
/safari-extension:/i,
/mypersonalassistant/i,
],
initialScope: {
tags: {
project: 'novalon-website',
version: process.env.npm_package_version || 'unknown',
deployment: process.env.NODE_ENV || 'unknown',
},
user: {
id: 'anonymous',
segment: 'visitor',
},
},
beforeSend(event) {
if (event.request?.url) {
event.request.url = event.request.url.replace(/\/[a-f0-9]{32}/gi, '/[hash]');
}
if (event.breadcrumbs) {
event.breadcrumbs = event.breadcrumbs.filter((breadcrumb) => {
return !(
breadcrumb.category === 'console' &&
breadcrumb.level === 'log'
);
});
}
return event;
},
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration({
maskAllText: true,
blockAllMedia: true,
}),
],
});
console.log('[Sentry] Client-side monitoring initialized');
} else {
console.warn('[Sentry] NEXT_PUBLIC_SENTRY_DSN not configured, error monitoring disabled');
}
// App Router 导航插桩钩子(见文件头注释;仅声明函数引用,无副作用,DSN 缺失时 SDK 未 init 也不会发送)
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;