Replies: 1 comment
-
Hi @RoysyLee 👋 — great question! You can already achieve domain-based trace separation today using OpenTelemetry’s built-in HTTP instrumentation. Here’s how: ✅ Option 1: Add Domain Info via
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
No response
Background
In a SaaS environment, each customer may have a different domain. However, with the current OpenTelemetry setup, it is not possible to separate or distinguish requests based on domain information in the traces.
https://nextjs.org/docs/app/guides/open-telemetry#default-spans-in-nextjs
We attempted to add a custom span tag in the middleware to include domain details. However, in version 15.3, it appears that span tags cannot be added from middleware, making this approach unfeasible.
As a result, OpenTelemetry cannot be effectively used with Next.js in a SaaS context, since domain-based trace separation is essential for observability across multiple tenants.
Our service is not deployed via Vercel, but instead uses Docker-based deployment on a cloud environment. Therefore, we need a more flexible and production-grade observability setup that works outside the Vercel ecosystem.
Proposal
Allow adding custom span tags within Next.js middleware.
This would enable us to inject dynamic information such as the request's domain or tenant identifier at an early stage in the request lifecycle.
Include host (domain) information in the default OpenTelemetry span.
This would allow domain-level trace separation out of the box, without requiring custom instrumentation in middleware or handlers.
Beta Was this translation helpful? Give feedback.
All reactions