-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Add
instrumentation.ts
API reference, improve instrumentation…
… docs (#61403) - Add instrumentation.ts API reference - Polish and restructure instrumentation docs
- Loading branch information
1 parent
68c5edf
commit 91cbe61
Showing
4 changed files
with
121 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
docs/02-app/02-api-reference/02-file-conventions/instrumentation.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
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 | |
21 changes: 21 additions & 0 deletions
21
docs/02-app/02-api-reference/05-next-config-js/instrumentationHook.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
title: instrumentationHook | ||
description: Use the instrumentationHook option to set up instrumentation in your Next.js App. | ||
related: | ||
title: Learn more about Instrumentation | ||
links: | ||
- app/api-reference/file-conventions/instrumentation | ||
- app/building-your-application/optimizing/instrumentation | ||
--- | ||
|
||
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} | ||
|
||
The experimental `instrumentationHook` option allows you to set up instrumentation via the [`instrumentation` file](/docs/app/api-reference/file-conventions/instrumentation) in your Next.js App. | ||
|
||
```js filename="next.config.js" | ||
module.exports = { | ||
experimental: { | ||
instrumentationHook: true, | ||
}, | ||
} | ||
``` |
7 changes: 7 additions & 0 deletions
7
docs/03-pages/02-api-reference/03-next-config-js/instrumentationHook.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: instrumentationHook | ||
description: Use the instrumentationHook option to set up instrumentation in your Next.js App. | ||
source: app/api-reference/next-config-js/instrumentationHook | ||
--- | ||
|
||
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} |