Skip to content

Commit deca76b

Browse files
committed
doc: diff between instrumentation vs instrumentation-client
1 parent cca78ec commit deca76b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/01-app/04-api-reference/05-config/01-next-config-js/clientInstrumentationHook.mdx

+30
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,33 @@ const nextConfig = {
3434

3535
module.exports = nextConfig
3636
```
37+
38+
## Example
39+
40+
Unlike server-side [instrumentation](/docs/app/building-your-application/optimizing/instrumentation), `instrumentation-client.ts` does not need to export a `register` function. You can write your synchronous code directly in the file:
41+
42+
```ts filename="instrumentation-client.ts" switcher
43+
// No need to export a register function
44+
// This code runs synchronously before hydration
45+
console.log('Client instrumentation initialized')
46+
// Set up performance monitoring
47+
performance.mark('app-init')
48+
// Set up error tracking
49+
window.addEventListener('error', (event) => {
50+
console.error('Captured in instrumentation:', event.error)
51+
// Send to your error tracking service
52+
})
53+
```
54+
55+
```js filename="instrumentation-client.js" switcher
56+
// No need to export a register function
57+
// This code runs synchronously before hydration
58+
console.log('Client instrumentation initialized')
59+
// Set up performance monitoring
60+
performance.mark('app-init')
61+
// Set up error tracking
62+
window.addEventListener('error', (event) => {
63+
console.error('Captured in instrumentation:', event.error)
64+
// Send to your error tracking service
65+
})
66+
```

0 commit comments

Comments
 (0)