Next.js
Initialize CheckUpstream in the Node.js branch of instrumentation.ts to measure outbound fetch calls. This App Router example uses after() to flush telemetry after the response; it does not configure Edge runtime or browser monitoring.
1. Install
npm install @checkupstream/sdk2. Register the instrumentation hook
Create instrumentation.ts beside your app directory, or inside src if you use it. Next.js calls this hook in each runtime, so import the Node.js SDK conditionally. The helper reads CHECKUPSTREAM_SDK_KEY from your server environment. See Next.js instrumentation.
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const { register: registerCheckUpstream } = await import(
"@checkupstream/sdk/integrations/next"
);
registerCheckUpstream();
}
}Explicit configuration
Pass configuration explicitly (optional)
Use initCheckUpstream instead and pass the same options the Node.js SDK accepts.
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const { initCheckUpstream } = await import(
"@checkupstream/sdk/integrations/next"
);
const sdkKey = process.env.CHECKUPSTREAM_SDK_KEY;
if (!sdkKey) throw new Error("Set CHECKUPSTREAM_SDK_KEY before starting the app");
initCheckUpstream({
sdkKey,
environment: process.env.VERCEL_ENV ?? "development",
services: ["api.github.com", "api.stripe.com"],
});
}
}3. Flush before the function shuts down
Serverless runtimes can freeze a request as soon as the response ships. after() runs once the response is sent, so the SDK has time to drain its buffer.
import { after } from "next/server";
import { flushTelemetry } from "@checkupstream/sdk/integrations/next";
export const runtime = "nodejs";
export async function GET() {
const response = await fetch("https://api.github.com/zen");
const data = await response.text();
after(flushTelemetry);
return Response.json(data);
}The zero-config register helper reads CHECKUPSTREAM_DEBUG=true for SDK diagnostic logging. When using initCheckUpstream, pass debug: true explicitly. Confirm that a test request appears in your project before relying on the integration.
Continue your setup
Check runtime availability and credentials before deploying an integration.