instrumentation-client.js
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.
To use it, place the file in the root of your application or inside a src
folder.
Usage
Unlike server-side instrumentation, you don't need to export any specific functions. Simply write your monitoring code directly in the file:
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)
})
Was this helpful?