Skip to content

instrumentation-client.js

instrumentation-client.js|ts 文件允许你添加在应用前端代码开始执行之前运行的监控和分析代码。这对于设置性能跟踪、错误监控或任何其他客户端可观察性工具非常有用。

¥The instrumentation-client.js|ts file allows you to add monitoring and analytics code that runs before your application's frontend code starts executing. This is useful for setting up performance tracking, error monitoring, or any other client-side observability tools.

要使用它,请将文件放在应用的根目录或 src 文件夹中。

¥To use it, place the file in the root of your application or inside a src folder.

用法

¥Usage

服务器端检测 不同,你无需导出任何特定函数。你可以直接在文件中编写监控代码:

¥Unlike server-side instrumentation, you do not need to export any specific functions. You can write your monitoring code directly in the file:

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)
})
js
// 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)
})

版本历史

¥Version History

版本更改
v15.3instrumentation-client 介绍

Next.js v15.3 中文网 - 粤ICP备13048890号