Next.js App Router Wrapper
The Astralog Next.js wrapper is designed specifically for Serverless architectures. It ensures that all events are force-flushed to ClickHouse before the Vercel Edge instance or AWS Lambda suspends, guaranteeing zero data loss.
Installation
npm install astralog-nextjs astralog-node
Setup (App Router)
// app/api/checkout/route.ts
import { NextResponse } from "next/server";
import { Client } from "astralog-node";
import { withAstralog } from "astralog-nextjs";
const client = new Client({ apiKey: "ast_sk_live_xxxxxxxxxxxxx" });
async function handler(req: Request) {
// Business logic
client.info("Processing checkout from Edge", { req_url: req.url });
return NextResponse.json({ status: "success" });
}
// Export the wrapped handler so Astralog intercepts it and forces a flush
export const POST = withAstralog(client, handler);
Anti-Serverless Suspension
Vercel and AWS Lambda automatically freeze the container execution milliseconds after returning the HTTP response. Traditional logging background workers fail in these environments because their intervals never trigger.
The withAstralog wrapper intercepts the completion of your route handler and automatically performs an await client.flush() before returning the NextResponse to the client. This guarantees 100% data durability without complex edge configurations.