Troubleshooting OpenTelemetry: instrumentation.ts never imported
Unanswered
Masai Lion posted this in #help-forum
Masai LionOP
Hello, I have been trying to set up OpenTelemetry instrumentation. I followed the instructions here: https://nextjs.org/docs/app/building-your-application/optimizing/open-telemetry
In particular I created instrumentation.ts in my project root, like this:
And I created next.config.js like this:
I see the following console output when I start the server with "next dev"
But I do not see the following output, which you see when you start the
I also do not see the console.log statements I added to instrumentation.ts:
So it seems like the instrumentationHook is getting installed, but instrumentation.ts is getting ignored. The
I would appreciate any insight anyone could share on this. Thank you.
In particular I created instrumentation.ts in my project root, like this:
$ cat src/instrumentation.ts
import { registerOTel } from '@vercel/otel'
console.log('instrumentation here0')
export function register() {
console.log('instrumentation here1')
registerOTel("yourpeer");
}And I created next.config.js like this:
$ cat next.config.js
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
instrumentationHook: true,
},
};I see the following console output when I start the server with "next dev"
▲ Next.js 14.2.5
- Local: http://localhost:3001
- Environments: .env.local
- Experiments (use with caution):
· instrumentationHook
✓ Starting...
✓ Ready in 2.4sBut I do not see the following output, which you see when you start the
with-opentelemetry-app example: ○ Compiling /instrumentation ...
✓ Compiled /instrumentation in 853ms (147 modules)I also do not see the console.log statements I added to instrumentation.ts:
instrumentation here0 and instrumentation here1So it seems like the instrumentationHook is getting installed, but instrumentation.ts is getting ignored. The
with-opentelemetry-app example is working fine, but I can't get telemetry enabled in my application. Am I missing something?I would appreciate any insight anyone could share on this. Thank you.