Skip to content

Opentelemetry is not collecting http_server_request_duration_bucket metrics for Nextjs endpoints #80262

Open
@estigma88

Description

@estigma88

Link to the code that reproduces this issue

https://github.com/estigma88/opentelemetry-nextjs-issue

To Reproduce

  1. Clone the following project https://github.com/vercel/opentelemetry-collector-dev-setup/tree/main
  2. Run the docker-compose up to start up Prometheus and the otel-collector
  3. Clone https://github.com/estigma88/opentelemetry-nextjs-issue
  4. Run the nextjs app with npm run dev
  5. Go to http://localhost:3000/ several times
  6. Wait for a while for the metrics to be collected
  7. Go to Prometheus in http://0.0.0.0:9090/query
  8. Explore the metrics, you will see http_client_request_duration_bucket but not http_server_request_duration_bucket

Current vs. Expected behavior

Http 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.

Provide environment information

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/opening-an-issue

Which area(s) are affected? (Select all that apply)

Instrumentation

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

This is how metrics look in Prometheus:

Image

Interestingly enough, traces are collected fine for endpoints:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    InstrumentationRelated to Next.js Instrumentation.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions