This is a Next.js minimal reproduction demonstrating a bug with OpenTelemetry tracing when using a custom server.
When using a custom Next.js server with OpenTelemetry tracing, the BaseServer.handleRequest span is missing http.route and next.route attributes. These attributes are correctly present when using the built-in Next.js server.
This repository contains two server configurations:
- Custom Server (
npm start) - Demonstrates the bug - Built-in Server (
npm run start:regular) - Shows expected behavior
# Install dependencies
npm install
# Build the app
npm run build
# Test with custom server
npm start
# In another terminal: curl http://localhost:<port>/
# Test with built-in server
npm run start:regular
# In another terminal: curl http://localhost:3456/attributes: {
'next.span_name': 'GET',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target': '/',
'http.status_code': 200,
'next.rsc': false
// ❌ MISSING 'next.route': '/'
// ❌ MISSING 'http.route': '/'
}attributes: {
'next.span_name': 'GET /',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target': '/',
'http.status_code': 200,
'next.rsc': false,
// ✅ HAS 'next.route': '/'
// ✅ HAS 'http.route': '/'
}When using a custom server with OpenTelemetry, the BaseServer.handleRequest span is missing both http.route and next.route attributes, even though these attributes are correctly present when using the built-in Next.js server.
This is a significant issue for observability, as these route attributes are crucial for:
- Grouping requests by route in APM tools
- Setting up alerts based on specific routes
- Understanding performance patterns per route
These are the steps you should follow when creating a bug report:
- Bug reports must be verified against the
next@canaryrelease. The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. Think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces before opening a new issue. Issues not verified againstnext@canarywill be closed after 30 days. - Make sure your issue is not a duplicate. Use the GitHub issue search to see if there is already an open issue that matches yours. If that is the case, upvoting the other issue's first comment is desirable as we often prioritize issues based on the number of votes they receive. Note: Adding a "+1" or "same issue" comment without adding more context about the issue should be avoided. If you only find closed related issues, you can link to them using the issue number and
#, eg.:I found this related issue: #3000. - If you think the issue is not in Next.js, the best place to ask for help is our Discord community or GitHub discussions. Our community is welcoming and can often answer a project-related question faster than the Next.js core team.
- Make the reproduction as minimal as possible. Try to exclude any code that does not help reproducing the issue. E.g. if you experience problems with Routing, including ESLint configurations or API routes aren't necessary. The less lines of code is to read through, the easier it is for the Next.js team to investigate. It may also help catching bugs in your codebase before publishing an issue.
- Don't forget to create a new repository on GitHub and make it public so that anyone can view it and reproduce it.
Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example reproduction-template reproduction-appyarn create next-app --example reproduction-template reproduction-apppnpm create next-app --example reproduction-template reproduction-appTo learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
- How to Contribute to Open Source (Next.js) - a video tutorial by Lee Robinson
- Triaging in the Next.js repository - how we work on issues
- CodeSandbox - Edit this repository on CodeSandbox
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
If your reproduction needs to be deployed, the easiest way is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.