Next.js
Set up OneMinute Logs in Next.js.
Install the SDK, create your API key, initialize the server-side logger, and start sending structured, OpenTelemetry-aligned events from route handlers, server actions, or backend utilities.
If you are using Cursor, Claude Code, Codex, Antigravity, or any other AI IDE, follow our Setup with AI guide.
1. Install the SDK
Add the OneMinute Logs SDK for this framework.
npm install @oneminutelogs/next2. Create an API key
Create an API key from your OneMinute Logs dashboard and add it to your environment variables. Open the API key guide.
ONE_MINUTE_LOGS_API_KEY=your_oml_api_key3. Create lib/logs.ts
Initialize the logger once and import it anywhere you need to send events.
import { createLogger } from "@oneminutelogs/next";
export const log = createLogger({
apiKey: process.env.ONE_MINUTE_LOGS_API_KEY!,
projectName: "my-next-app",
environment: process.env.NODE_ENV || "development",
});Create the logger in a server-only module like lib/logs.ts and import it from route handlers or server actions. Never import it into a client component — it holds your API key.
4. Send events
Log at a level — trace, debug, info, warn, error, or fatal — and attach a stable eventName plus structured attributes for anything you might filter or alert on.
import { log } from "@/lib/logs";
export async function POST(request: Request) {
const order = await createOrder(await request.json());
await log.info({
message: "Order created",
eventName: "order.created",
attributes: {
"order.id": order.id,
"order.total": order.total,
"user.id": order.userId,
},
});
try {
await charge(order);
} catch (err) {
await log.error({
message: "Payment failed",
eventName: "payment.charge.failed",
attributes: {
"payment.provider": "stripe",
"error.type": (err as Error).name,
"user.id": order.userId,
},
});
throw err;
}
return Response.json({ ok: true });
}What's next?
Alerts
Create alert rules from your production events.
Webhooks
Send verified notifications to your own endpoint.
Live Events
Stream incoming events into your own dashboard.
Search & Filters
Query stored events with filters and search terms.
After events are flowing, alerts, webhooks, live dashboards, and search all work from the same event pipeline.