Public documentation
Documentation indexRead as MarkdownVercel: Next.js and trace export
Use Corridora RUM in the page and a runtime-aware trace exporter for server execution. The direct-export example below targets Next.js Node.js route handlers. A native Vercel Trace Drain is an alternative export route when available to your team.
Choose one intended export path for application spans. Sending the same spans through both a custom exporter and a drain can produce duplicates.
Prerequisites
- An existing Next.js application deployed to Vercel, with permission to edit its environment and redeploy.
- A supported, mutually compatible Next.js and OpenTelemetry dependency set, recorded in your lockfile.
- A backend Corridora ingest key and a separate browser RUM key in the same organization.
- An uncached API route that executes in Node.js, with your normal application access controls.
Static output and responses served entirely from cache do not execute a new route-handler span. Test an actual function invocation.
Option A: export from the Node.js application
Install the application dependencies:
npm install @vercel/otel @opentelemetry/api @opentelemetry/api-logs \
@opentelemetry/exporter-trace-otlp-http
Copy instrumentation.ts and instrumentation.node.ts beside app/, or inside src/ beside src/app/. Merge into an existing instrumentation hook instead of registering a second SDK.
The entry point isolates the Node-only exporter from other runtimes:
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
await import("./instrumentation.node");
}
}
The Node configuration exports OTLP/HTTP JSON to the complete traces URL and sets the credential explicitly:
traceExporter: new OTLPTraceExporter({
url: "https://ingest.corridora.ai/v1/traces",
headers: { "X-CORRIDORA-KEY": ingestKey },
})
The complete file includes imports, key validation, resource attributes, and a downstream fetch propagation rule. Replace the example API origin and service identity. Keep controlled downstream destinations in propagateContextUrls; this setting is separate from the browser agent's origin list.
In Vercel's project environment variables, add CORRIDORA_INGEST_KEY for the environments you deploy. Mark it sensitive where the environment supports that setting. Do not prefix the variable with NEXT_PUBLIC_. Redeploy after changing it; existing deployments retain their earlier configuration.
This installation owns tracing through @vercel/otel. Do not also apply a container-style Node --require auto-instrumentation preload.
Add a verification route
Copy route.ts to app/api/trace-check/route.ts, or src/app/api/trace-check/route.ts. It returns the current trace ID, sets Cache-Control: no-store, and explicitly selects runtime = "nodejs".
Use the route in a staging environment or protect it through the application's existing controls. After RUM initializes, request /api/trace-check from the page. Compare the returned ID to the request's traceparent, then find the resulting span in Corridora. Returning an ID alone does not prove delivery.
Option B: configure a native Trace Drain
Vercel currently exposes Drains on Pro and Enterprise teams. With the necessary team permissions:
- Open Team Settings → Drains → Add Drain.
- Choose Traces, select the intended projects and environments through the drain configuration, and choose a Custom Endpoint.
- Set the destination to
https://ingest.corridora.ai/v1/traces, or your installation's equivalent. - Choose OTLP/HTTP protobuf or OTLP JSON. Corridora accepts both. An OTLP/gRPC address is not a valid Trace Drain destination.
- Add the custom header
X-CORRIDORA-KEY: YOUR_BACKEND_INGEST_KEY. - Configure sampling to include the tested environment and path, save the drain, and verify actual delivery.
For Node application instrumentation using this route, let @vercel/otel select Vercel's export mechanism instead of passing the custom exporter from Option A:
import { registerOTel } from "@vercel/otel";
export function register() {
registerOTel({ serviceName: "shop-api-vercel" });
}
Configure downstream fetch propagation here as needed. A drain forwards available platform/application trace data; it does not instrument an unsupported library or generate browser RUM data. A Vercel Log Drain is a separate payload format and should not be assumed interchangeable with Corridora's OTLP /v1/logs endpoint.
Browser and runtime boundaries
Install RUM in the page bootstrap before the requests you want to trace. Same-origin API fetches are eligible automatically; controlled cross-origin APIs need the exact origin allowlist and CORS permission for traceparent.
Next.js supports incoming trace-context extraction. Verify that middleware, rewrites, authentication, and any upstream proxy preserve that context. Vercel's platform sampling can omit data even when the incoming browser context is sampled; native-drain sampling adds another retention decision.
The Node exporter example does not instrument Edge-runtime functions. Current Vercel documentation excludes custom spans from Edge-runtime functions. Use the native platform data that your deployment actually exposes, and verify its trace IDs and headers before claiming a connected edge trace. For a reliable instrumented API path, use the Node.js route setup or a separately instrumented origin.
Verify after deployment
Run deployment verification on both a cold and a warm invocation. Confirm a browser CLIENT span and backend SERVER span share the trace ID and that the expected child spans appear. Check actual stored spans after the function returns to detect lifecycle/export gaps.
If local traces work but deployed traces do not, inspect environment targeting, deployment age, export mode, sampling rules, and the selected runtime. If a cached response returns an old trace ID, bypass caching before using it as a new-request test.