instrumentation-client.js
instrumentation-client.js|ts
文件允许你添加监控和分析代码,这些代码在你的应用程序前端代码开始执行之前运行。这对于设置性能跟踪、错误监控或任何其他客户端可观察性工具非常有用。
要使用它,请将文件放置在应用程序的根目录或 src
文件夹中。
用法
与服务器端检测不同,你不需要导出任何特定的函数。你可以直接在文件中编写你的监控代码
instrumentation-client.ts
// Set up performance monitoring
performance.mark('app-init')
// Initialize analytics
console.log('Analytics initialized')
// Set up error tracking
window.addEventListener('error', (event) => {
// Send to your error tracking service
reportError(event.error)
})
版本历史
版本 | 变更 |
---|---|
v15.3 | 引入了 instrumentation-client |
这有帮助吗?