91cbe61e75
- Add instrumentation.ts API reference - Polish and restructure instrumentation docs
53 lines
1.8 KiB
Text
53 lines
1.8 KiB
Text
---
|
|
title: instrumentation.js
|
|
description: API reference for the instrumentation.js file.
|
|
related:
|
|
title: Learn more about Instrumentation
|
|
links:
|
|
- app/building-your-application/optimizing/instrumentation
|
|
---
|
|
|
|
The `instrumentation.js|ts` file is used to integrate monitoring and logging tools into your application. This allows you to track the performance and behavior of your application, and to debug issues in production.
|
|
|
|
To use it, place the file in the **root** of your application or inside a [`src` folder](/docs/app/building-your-application/configuring/src-directory) if using one.
|
|
|
|
## Config Option
|
|
|
|
Instrumentation is currently an experimental feature, to use the `instrumentation` file, you must explicitly opt-in by defining [`experimental.instrumentationHook = true;`](/docs/app/api-reference/next-config-js/instrumentationHook) in your `next.config.js`:
|
|
|
|
```js filename="next.config.js"
|
|
module.exports = {
|
|
experimental: {
|
|
instrumentationHook: true,
|
|
},
|
|
}
|
|
```
|
|
|
|
## Exports
|
|
|
|
### `register` (required)
|
|
|
|
The file exports a `register` function that is called **once** when a new Next.js server instance is initiated. `register` can be an async function.
|
|
|
|
```ts filename="instrumentation.ts" switcher
|
|
import { registerOTel } from '@vercel/otel'
|
|
|
|
export function register() {
|
|
registerOTel('next-app')
|
|
}
|
|
```
|
|
|
|
```js filename="instrumentation.js" switcher
|
|
import { registerOTel } from '@vercel/otel'
|
|
|
|
export function register() {
|
|
registerOTel('next-app')
|
|
}
|
|
```
|
|
|
|
## Version History
|
|
|
|
| Version | Changes |
|
|
| --------- | ------------------------------------------------------- |
|
|
| `v14.0.4` | Turbopack support for `instrumentation` |
|
|
| `v13.2.0` | `instrumentation` introduced as an experimental feature |
|