Express.js
Set up OneMinute Logs in Express.js.
Install the Express SDK, register its middleware, and send structured, OpenTelemetry-aligned events through the logger attached to each request.
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/express2. 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 src/app.ts
Initialize the logger once and import it anywhere you need to send events.
import express from "express";
import { withOneMinuteLogs } from "@oneminutelogs/express";
const app = express();
app.use(express.json());
app.use(
withOneMinuteLogs(
{
apiKey: process.env.ONE_MINUTE_LOGS_API_KEY!,
projectName: "my-express-api",
environment: process.env.NODE_ENV || "development",
},
{ autoLogRequests: true }, // optional: one log per completed request
),
);The middleware attaches a type-safe logger to req.logger. With { autoLogRequests: true } it also emits one http.server.request event per completed request; leave it off (the default) to keep control of what gets logged.
Standalone logger for workers and scripts
Outside an Express request, create one logger and reuse it in background jobs or command-line scripts.
import { createLogger } from "@oneminutelogs/express";
export const logger = createLogger({
apiKey: process.env.ONE_MINUTE_LOGS_API_KEY!,
projectName: "my-express-worker",
environment: process.env.NODE_ENV || "development",
});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.
// Continue in src/app.ts
app.post("/checkout", async (req, res) => {
try {
const order = await createOrder(req.body);
await req.logger.info({
message: "Payment succeeded",
eventName: "payment.charge.succeeded",
attributes: {
"payment.provider": "stripe",
"payment.amount": order.amount,
"payment.currency": "usd",
"order.id": order.id,
"user.id": req.user.id,
},
});
res.json({ ok: true });
} catch (error) {
await req.logger.error({
message: "Payment failed",
eventName: "payment.charge.failed",
attributes: {
"payment.provider": "stripe",
"error.type": (error as Error).name,
"user.id": req.user.id,
},
});
res.status(500).json({ ok: false });
}
});
app.listen(3000);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.