Metrics Docs
Vercel
Send metrics from a Vercel-hosted Next.js route handler into Distlang Metrics.
Add the token to your project
Create a DISTLANG_ACCESS_TOKEN environment variable in your Vercel project settings.
Example Next.js route handler
import { after } from "next/server";
import { createDistlangClient } from "@distlang/client";
const client = createDistlangClient();
export async function GET() {
const startedAt = Date.now();
const metrics = client.metrics.createRecorder({
accessToken: process.env.DISTLANG_ACCESS_TOKEN,
metricSet: "vercel-app",
definitions: {
requestCount: "counter",
latencyMs: "histogram",
},
});
metrics.requestCount.inc({ route: "/api/ping", method: "GET", status: "200" });
metrics.latencyMs.observe(Date.now() - startedAt, { route: "/api/ping", method: "GET" });
after(async () => {
await metrics.flush();
});
return Response.json({ ok: true });
}
Why this is the default Vercel example
Most Vercel users already have Next.js route handlers in place, so this is the shortest path from an existing app to visible metrics.
Notes
- Keep
metricSetstable across deploys - Use
after(...)so metrics flushing does not block the response path - Keep labels bounded and predictable
For non-Next.js Vercel Functions, use waitUntil(...) from @vercel/functions instead.