HTTP server metrics are not being collected due to initialization timing issues with Next.js.
The issue involves OpenTelemetry not collecting HTTP server metrics for Next.js endpoints, likely due to initialization timing where Next.js starts before OpenTelemetry can patch the HTTP module. The solution requires ensuring proper initialization order or patching, but there's uncertainty about the exact approach due to version-specific behavior and maintainer comments indicating complexity.
https://github.com/estigma88/opentelemetry-nextjs-issue
docker-compose up to start up Prometheus and the otel-collectornpm run devhttp_client_request_duration_bucket but not http_server_request_duration_bucketHttp client metrics are collected but not Http server metrics.
The following is the Opentelemetry configuration:
const sdk = new opentelemetry.NodeSDK({
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'next-app',
}),
traceExporter: new OTLPTraceExporter(),
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
}),
instrumentations: [getNodeAutoInstrumentations()],
});
sdk.start();
Same configuration using Express works fine.
Operating System:
Platform: linux
Arch: x64
Version: #63-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 19:04:15 UTC 2025
Available memory (MB): 31731
Available CPU cores: 12
Binaries:
Node: 20.16.0
npm: 10.8.1
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 15.4.0-canary.29 // There is a newer canary version (15.4.0-canary.69) available, please upgrade!
eslint-config-next: N/A
react: 18.3.1
react-dom: 18.3.1
typescript: 4.7.4
Next.js Config:
output: N/A
⚠ There is a newer canary version (15.4.0-canary.69) available, please upgrade!
Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
Read more - https://nextjs.org/docs/messages/open
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!