mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 21:05:51 +00:00
perf: 优化内存与遥测管理,启用 Vite minify
- 禁用 HISTORY_SNIP feature flag 并新增 proactiveTruncate 防止无 compact_boundary 时内存无限增长 - 跳过未启用 telemetry 时的 OTel 初始化,防止长会话 PerformanceMeasure 堆积 - OTel 导出遇 401/403 自动关闭 reader,防止 handle 泄漏 - Vite 构建启用 minify Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -206,10 +206,49 @@ async function getOtlpReaders() {
|
||||
|
||||
return exporters.map(exporter => {
|
||||
if ('export' in exporter) {
|
||||
return new PeriodicExportingMetricReader({
|
||||
const reader = new PeriodicExportingMetricReader({
|
||||
exporter,
|
||||
exportIntervalMillis: exportInterval,
|
||||
})
|
||||
// Wrap the export callback to auto-shutdown the reader on auth
|
||||
// failures (401/403). Without this the PeriodicExportingMetricReader's
|
||||
// internal setInterval keeps retrying forever, leaking handles.
|
||||
const originalExport = (
|
||||
exporter as unknown as {
|
||||
export: (
|
||||
metrics: unknown,
|
||||
callback: (result: { error?: Error }) => void,
|
||||
) => unknown
|
||||
}
|
||||
).export.bind(exporter)
|
||||
;(
|
||||
exporter as unknown as {
|
||||
export: (
|
||||
metrics: unknown,
|
||||
callback: (result: { error?: Error }) => void,
|
||||
) => unknown
|
||||
}
|
||||
).export = (metrics, callback) => {
|
||||
return originalExport(metrics, result => {
|
||||
if (result.error) {
|
||||
const msg = result.error.message || ''
|
||||
if (
|
||||
msg.includes('401') ||
|
||||
msg.includes('403') ||
|
||||
msg.includes('Unauthorized') ||
|
||||
msg.includes('authentication')
|
||||
) {
|
||||
logForDebugging(
|
||||
`[3P telemetry] Auth error detected, shutting down metric reader`,
|
||||
{ level: 'error' },
|
||||
)
|
||||
void reader.shutdown()
|
||||
}
|
||||
}
|
||||
callback(result)
|
||||
})
|
||||
}
|
||||
return reader
|
||||
}
|
||||
return exporter
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user