-
Notifications
You must be signed in to change notification settings - Fork 29k
Open
Labels
InstrumentationRelated to Next.js Instrumentation.Related to Next.js Instrumentation.MiddlewareRelated to Next.js Middleware.Related to Next.js Middleware.
Description
Link to the code that reproduces this issue
https://github.com/r34son/nextjs-handle-request-span-repro
To Reproduce
- Start Jaeger:
pnpm jaeger
- Run app in second terminal:
pnpm dev
- Open http://localhost:3000 in browser
- View traces at http://localhost:16686
Current vs. Expected behavior
Current Behavior
-
Trace Fragmentation:
- Middleware and page executions appear as completely separate traces in Jaeger:
- One trace for middleware with `next.span_type` "BaseServer.handleRequest":
- Separate trace for page render with `next.span_type` "BaseServer.handleRequest":
- Edge Runtime Middleware Limitations:
- Edge middleware shows no OpenTelemetry spans (no custom, and fetch) - see screen above
- Only Node middleware produces traces (you can repro on node-middleware branch):
Expected Behavior
-
Unified Tracing:
- Single end-to-end trace for each request
-
Edge Runtime Support:
- Consistent tracing capabilities across Edge and Node runtimes
- Basic span creation and instrumentation in Edge middleware
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:39 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6020
Available memory (MB): 32768
Available CPU cores: 12
Binaries:
Node: 22.15.0
npm: 10.9.2
Yarn: N/A
pnpm: 10.9.0
Relevant Packages:
next: 15.3.2 // Latest available version is detected (15.3.2).
eslint-config-next: N/A
react: 19.1.0
react-dom: 19.1.0
typescript: 5.8.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
Trying to add custom logging for requests. See https://github.com/r34son/nextjs-handle-request-span-repro/blob/main/access-log-span-processor.ts. But middleware and page rendering generate separate traces in OpenTelemetry, rather than a single unified trace for the complete request lifecycle.
r34son, stg35, zloit and theStrangeAdventurer
Metadata
Metadata
Assignees
Labels
InstrumentationRelated to Next.js Instrumentation.Related to Next.js Instrumentation.MiddlewareRelated to Next.js Middleware.Related to Next.js Middleware.