Skip to content

Commit

Permalink
[Docs] Add note about adding the instrumentation file inside 'src' (#…
Browse files Browse the repository at this point in the history
…51415)

The instrumentation.js should be placed in the root, or inside the 'src' folder if one exists
  • Loading branch information
delbaoliveira committed Jun 16, 2023
1 parent a3ef99a commit 13c205f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To get started, you must install `@vercel/otel`:
npm install @vercel/otel
```

Next, create a custom [`instrumentation.ts`](/docs/pages/building-your-application/optimizing/instrumentation) (or `.js`) file in the **root directory** of the project:
Next, create a custom [`instrumentation.ts`](/docs/pages/building-your-application/optimizing/instrumentation) (or `.js`) file in the **root directory** of the project (or inside `src` folder if using one):

```ts filename="your-project/instrumentation.ts" switcher
import { registerOTel } from '@vercel/otel'
Expand All @@ -55,7 +55,7 @@ export function register() {

> **Good to know**
>
> - The `instrumentation` file should be in the root of your project and not the `app` or `pages` directory.
> - The `instrumentation` file should be in the root of your project and not inside the `app` or `pages` directory. If you're using the `src` folder, then place the file inside `src` alongside `pages` and `app`.
> - If you use the [`pagesExtension` config option](/docs/pages/api-reference/next-config-js/pageExtensions) to add a suffix, you will also need to update the `instrumentation` filename to match.
> - We have created a basic [with-opentelemetry](https://github.com/vercel/next.js/tree/canary/examples/with-opentelemetry) example that you can use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ title: Instrumentation
description: Learn how to use instrumentation to run code at server startup in your Next.js app
---

> **Good to know**: This feature is **experimental**. To use it, you must explicitly opt in by defining `experimental.instrumentationHook = true;` in your `next.config.js`.
If you export a function named `register` from a `instrumentation.ts` (or `.js`) file in the **root directory** of your project, we will call that function whenever a new Next.js server instance is bootstrapped.
If you export a function named `register` from a `instrumentation.ts` (or `.js`) file in the **root directory** of your project (or inside the `src` folder if using one), we will call that function whenever a new Next.js server instance is bootstrapped.

> **Good to know**
>
> - The `instrumentation` file should be in the root of your project and not the `app` or `pages` directory.
> - This feature is **experimental**. To use it, you must explicitly opt in by defining `experimental.instrumentationHook = true;` in your `next.config.js`.
> - The `instrumentation` file should be in the root of your project and not inside the `app` or `pages` directory. If you're using the `src` folder, then place the file inside `src` alongside `pages` and `app`.
> - If you use the [`pagesExtension` config option](/docs/pages/api-reference/next-config-js/pageExtensions) to add a suffix, you will also need to update the `instrumentation` filename to match.
> - We have created a basic [with-opentelemetry](https://github.com/vercel/next.js/tree/canary/examples/with-opentelemetry) example that you can use.
Expand Down

0 comments on commit 13c205f

Please sign in to comment.